Saturday, May 19, 2012

Insert flash/swf file in a master page

We can insert the flash/swf file in masterpage using the below code. 

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase=",0,40,0" id="sivaflash" style="width: 957px; height: 300px">
       <PARAM NAME=movie VALUE="/Style%20Library/siva/Banner.swf">
       <PARAM NAME=quality VALUE=High>
       <PARAM NAME=bgcolor VALUE=#ffffff>
       <param name="salign" value="T">
       <EMBED src="/Style%20Library/siva/Banner.swf" quality=High bgcolor=#ffffff
NAME="flash" ALIGN=""TYPE="application/x-shockwave-flash"
PLUGINSPAGE="" style="width: 957px; height: 300px" salign="T"></EMBED></OBJECT>

Thursday, May 10, 2012

All Language pack Code for Sharepoint 2010

Using the below power shell script to Download the Language Packs

Import-Module BitsTransfer
## Prompt for the destination path
$DestPath = Read-Host -Prompt "- Enter the destination path for downloaded files"
## Check that the path entered is valid
If (Test-Path "$DestPath" -Verbose)
    ## If destination path is valid, create folder if it doesn't already exist
    $DestFolder = "$DestPath\LanguagePacks"
    New-Item -ItemType Directory $DestFolder -ErrorAction SilentlyContinue
    Write-Warning " - Destination path appears to be invalid."
    ## Pause
    Write-Host " - Please check the path, and try running the script again."
    Write-Host "- Press any key to exit..."
    $null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
## We use the hard-coded URL below, so that we can extract the filename (and use it to get destination filename $DestFileName)
## Note: These URLs are subject to change at Microsoft's discretion.
$UrlList = ("", #Arabic
            "", #Basque
            "", #Bulgarian
            "", #Catalan
            "", #Chinese Simplified
            "", #Chinese Traditional
            "", #Croatian
            "", #Czech
            "", #Danish
            "", #Dutch
            "", #English
            "", #Estonian
            "", #Finnish
            "", #French
            "", #Galician
            "", #German
            "", #Greek
            "", #Hebrew
            "", #Hindi
            "", #Hungarian
            "", #Italian
            "", #Japanese
            "", #Kazakh
            "", #Korean
            "", #Latvian
            "", #Lithuanian
            "", #Norwegian
            "", #Polish
            "", #Portugese (Brazil)
            "", #Portugese (Portugal)
            "", #Romanian
            "", #Russian
            "", #Serbian (Latin)
            "", #Slovak
            "", #Slovenian
            "", #Spanish
            "", #Swedish
            "", #Thai
            "", #Turkish
            ""  #Ukranian
ForEach ($Url in $UrlList)
    ## Get the file name based on the portion of the URL after the last slash and replace the word "Server" with a random string
    ## (Crude way of getting unique file names since all Lang Packs are ServerLanguagePack.exe)
    $DestFileName = $Url.Split('/')[-1] -replace "Server",(Get-Random)
        ## Check if destination file already exists
        If (!(Test-Path "$DestFolder\$DestFileName"))
            ## Begin download
            Start-BitsTransfer -Source $Url -Destination $DestFolder\$DestFileName -DisplayName "Downloading `'$DestFileName`' to $DestFolder" -Priority High -Description "From $Url..." -ErrorVariable err
            If ($err) {Throw ""}
            Write-Host " - File $DestFileName already exists, skipping..."
        Write-Warning " - An error occurred downloading `'$DestFileName`'"
## View the downloaded files in Windows Explorer
Invoke-Item $DestFolder
## Pause
Write-Host "- Downloads completed, press any key to exit..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Link to a Document in another folder in document library

Link to a document in a document library when the document is stored/Updated in document library

Follow the below steps to do Link to a document using OOTB.

We use the Content Type “Link to a Document” to link to a document that could be stored in another document library.
If the document library where you want to use the “Link to a Document” hasn’t been setup to use Content Types, you’ll have to click Settings, Document Library Settings, there you’ll need to access the Advanced Settings.

We need to add a Content Type, but before we can do this we’ll have to tell our Document Library that it can make use of different Content Types. Select “Yes” for the “Allow management of Content Types“.

When you return to the Document Library Settings, you’ll see a new section called Content Types, this is where we’ll add a new Content Type, click “Add from exisiting Content Type“.

The content type we need is “Link to a Document“, add it here.

When you return to your Document Library and click new, you’ll see that you have a new option to choose from, “Link to a Document“.

Let’s make a link to a Document in another Document Library, click “Link to a Document”. You’ll have to enter a name for the Link and enter the path to the Document you want to link to.

After confirming this is what your link looks like.

We made link to a document that’s saved in another document library, whenever you make a change to the master document, you don’t need to worry about the link, it will point to the changed document.

In the same way we can put "link to a document" links in another folder with in the Documnet library using Object Mode, Here i am using Event handler to Create Link to document when new item is Added in Document Library

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using System.Text;

namespace LinkdocumentUrl.linktodocs
    /// <summary>
    /// List Item Events
    /// </summary>
    public class linktodocs : SPItemEventReceiver
       /// <summary>
       /// An item was added.
       /// </summary>
       public override void ItemAdded(SPItemEventProperties properties)
               using (SPSite site = new SPSite(properties.SiteId))
                   using (SPWeb web = site.AllWebs[properties.RelativeWebUrl])
                   //using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
                       SPListItem _item = properties.ListItem;
                       //SPField field = properties.ListItem.Fields.GetFieldByInternalName("Make a Link");
                       SPFieldBoolean boolField = _item.Fields["Make a Link"] as SPFieldBoolean;
                       bool CheckBoxValue = (bool)boolField.GetFieldValue(_item["Make a Link"].ToString());

                       //if (_item["Make a Link"].ToString() == "true")
                       if (CheckBoxValue== true)
                           string documentUrl = web.Url + "/" + properties.ListItem.Url;
                           string documentName = properties.ListItem.DisplayName.ToString();
                           SPList list = web.Lists["TestDocs"];

                           if (list is SPDocumentLibrary)
                               SPDocumentLibrary docLib = (SPDocumentLibrary)list;
                               //string libraryRelativePath = list.RootFolder.ServerRelativeUrl;
                               //string libraryPath = site.MakeFullUrl(libraryRelativePath);

                               SPFolder folder = web.GetFolder(site.MakeFullUrl(list.RootFolder.ServerRelativeUrl) + "/Public");
                               SPFileCollection filecoll = folder.Files;

                               if (docLib.ContentTypesEnabled)
                                   SPContentType myCType = list.ContentTypes["Link to a Document"];
                                   if (myCType != null)
                                       //replace string template with values
                                       string redirectAspx = RedirectAspxPage();
                                       redirectAspx.Replace("{0}", documentUrl);

                                       SPFile file = folder.Files.Add(documentName + ".aspx", UTF8Encoding.UTF8.GetBytes(redirectAspx));

                                       SPListItem item = file.Item;
                                       item["ContentTypeId"] = myCType.Id;
                                       SPFieldUrlValue fieldUrl = new SPFieldUrlValue() { Description = documentName, Url = documentUrl };
                                       item["URL"] = fieldUrl;




       public static string RedirectAspxPage()
           //StringBuilder builder = new StringBuilder();

           const string format = @"<%@ Assembly Name='Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c' %>
                                                <%@ Register TagPrefix='SharePoint' Namespace='Microsoft.SharePoint.WebControls' Assembly='Microsoft.SharePoint' %>
                                                <%@ Import Namespace='System.IO' %>
                                                <%@ Import Namespace='Microsoft.SharePoint' %>
                                                <%@ Import Namespace='Microsoft.SharePoint.Utilities' %>
                                                <%@ Import Namespace='Microsoft.SharePoint.WebControls' %>

                                                <html xmlns:mso='urn:schemas-microsoft-com:office:office' xmlns:msdt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'>
                                                <Head> <META Name='progid' Content='SharePoint.Link'>
                                                <!--[if gte mso 9]><xml>
                                                <mso:URL msdt:dt='string'>{0}, {0}</mso:URL>
                                                <mso:ContentType msdt:dt='string'>Link to a Document</mso:ContentType>
                                                        <form id='Form1' runat='server'>
                                                            <SharePoint:UrlRedirector id='Redirector1' runat='server' />
           StringBuilder builder = new StringBuilder(format.Length + 400);          
           builder.AppendFormat(format, typeof(SPDocumentLibrary).Assembly.FullName);          
           return builder.ToString();

Reference from