Archive for SharePoint Designer

MOSS:Back up and Restore Site Collection / Sites Using STSADM Utility Export / Import

STSADM.EXE utility export and import operations are used to backup and restore site collections and sites. These operations are limited to site collections and sites only.  

STSADM.EXE is usually located at “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN”. No GUI interface for the STSADM utility is available. The old and trusted command line is used for the utility. 

The backup contains library content, list content, navigation, user information, security settings, personalize settings like views and content types and customization but does not contain alerts, workflows and properties.  

BACKUP 

For backup, we use export operation which has the following syntax: 

stsadm -o export 

-url <URL name>

-filename <export file name>

[-overwrite]

[-includeusersecurity]

[-haltonwarning]

[-haltonfatalerror]

[-nologfile]

[-versions] <1-4>

[-cabsize] <integer value>

[-nofilecompression]

[-quiet] 

Parameter Description
url URL of the site collection / site
filename Name of the backup file
overwrite Overwrite the already existed backup file
includeusersecurity Maintain the security settings
haltonwarning Stop the export operation when a warning occur
haltonfatalerror Stop the export operation when an error occur
nologfile No log file will be generated at the end of the export operation.
versions Values ranges from 1 to 41-          Default value, last major versions of the files and list items included.2-          The current version, either the major or the last minor version included.3-           Last major and last minor version of the files and list items included.4-          All versions of the files and list items included.
cabsize Value ranges from 1 to 1024. set the total size of cabinet file. Once  size limit is reached, another cabinet file is created.
nofilecompression Disable file compression. If compression is allowed, export operation can increase by 30%
quiet Export operation information will not be displayed and operation will end with success message.

The command that I use to run is  

stsadm –o export –url htpp://URL –filename E:\backup\test.cab –includeusersecurity –versions 4 –cabsize 1024 –nofilecompression  

This command will create a directory test.cab. 

RESTORE 

First you have to create an empty website to restore. This can be done using Microsoft Office SharePoint Designer 2007.

For this, open Microsoft Office SharePoint Designer 2007 and move from File menu to New and click on Web Site. In the New Dialog box, select Web Site tab, then select General and then Empty Web Site. Give the desired URL  in the text box at the bottom of the dialog box and click OK. Microsoft Office SharePoint Designer 2007 will create a new empty web site.  

To restore, we use import operation which has the following syntax: 

stsadm -o import

-url <URL name>

-filename <import file name>

[-includeusersecurity]

[-haltonwarning]

[-haltonfatalerror]

[-nologfile]

[-updateversions] <1-3>

[-nofilecompression]

[-quiet] 

Parameter Description
url URL of the site
filename Name of the restore file
includeusersecurity Maintain the security settings
haltonwarning Stop the export operation when a warning occur
haltonfatalerror Stop the export operation when an error occur
nologfile No log file will be generated at the end of the export operation.
updatversions Values ranges from 1 to 31       Default value, will add new version to the current file.2        Overwrite the file and all of its versions.3       Ignore the file if it exists of the destination.
nofilecompression Either enables or disables file compression in the import package. The import package is stored in the folder specified by the -filename parameter. It is recommended to use this parameter for performance reasons. If compression is enabled, it can increase the import process by approximately 30%.
quiet Export operation information will not be displayed and operation will end with success message.

The command that I use to run is  

stsadm –o import –url htpp://URL –filename E:\backup\test.cab –includeusersecurity –updateversions 3  –nofilecompression  

Exception: 

Error occurred while exporting the web http://site URL

Access is denied.(Eception from RESULT:0×8007005(E_ACCESSDENIED)) 

Reason: 

You are not the administrator of the site collection. 

Resolution: 

Add yourself as site administrator. For this, open SharePoint Central Administration. Move from “Application Management” to “Site collection administrators” under  “SharePoint Site Management”. Add yourself as administrator in the appropriate site collection. 

 

http://office.microsoft.com/download/afile.aspx?AssetID=AM102424831033

 

http://technet2.microsoft.com/Office/en-us/library/1178aa35-20b1-45b0-bcb6-4249aa34ea481033.mspx?mfr=true

 

http://technet2.microsoft.com/Office/en-us/library/65788bb9-0345-42c8-a216-e99e558b173d1033.mspx?mfr=true

 

 

Comments

MOSS: Microsoft Office SharePoint Designer 2007 Restore Web Sites Error (Exportsettings.xml)

Exception:

error occured while importing the web http://SiteURL 

Could not find the file ‘C:\WINDOWS\TEMP\f611fafc-73d8-4b48-bc1e-f9ef6d7cb991\Exportsettings.xml’  

Reason: 

Microsoft Office SharePoint Designer 2007 failed to create a valid Content Migration Package (.cmp) for site having size greater than 25MB. Although, you will have a success message for backup but when you try to restore it, you will face the error of “Exportsettings.xml” file. The backup Content Migration Package (.cmp) can’t be restored. 

A typical “Exportsettings.xml” file has the following contents:  

<?xml version=”1.0″ encoding=”utf-8″ ?>

- <ExportSettings xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=”http://www.w3.org/2001/XMLSchema SiteUrl=”http://ServerName/ FileLocation=”PathOfTheBackupFile BaseFileName=”" IncludeSecurity=”None IncludeVersions=”All ExportPublicSchema=”true ExportMethod=”ExportAll ExcludeDependencies=”true xmlns=”urn:deployment-exportsettings-schema“>-

<ExportObjects> 

<DeploymentObject Id=”729ad10a-1ebf-48c1-bc95-ab2ffb7f5663 Type=”Web ParentId=”00000000-0000-0000-0000-000000000000 Url=”/URLOfTheSite ExcludeChildren=”false IncludeDescendants=”All” />  

</ExportObjects> 

</ExportSettings> 

The problem is that when “Microsoft Office SharePoint Designer 2007” tries to backup the site, WSS fail to create a valid Content Migration Package (.cmp). When, “Microsoft Office SharePoint Designer 2007” download first or some of the Content Migration Package (.cmp) files, other files are deleted. Thanks to the MOOS recycle bin, all the other (.cmp) files go straight to it. 

Resolution: 

The workaround for this problem requires “Microsoft Cabinet Software Development Kit”. Download Cabsdk.exe before proceeding. 

The first step is to take the backup of the site. (For details, follow the link). We name the Content Migration Package (.cmp) as “test.cmp”.Now when your try to restore the site using Content Migration Package (.cmp) “test.cmp”, you will face the error  

“error occured while importing the web http://SiteURL

Could not find the file ‘C:\WINDOWS\TEMP\f611fafc-73d8-4b48-bc1e-f9ef6d7cb991\Exportsettings.xml’ 

To restore the site, go to the Recycle bin of the site and there you will find the files with extension “.cmp”. Example name are like “D3F44E4819C24ED6AA9F7049E04AA431.cmp”, and “D3F44E4819C24ED6AA9F7049E04AA4311.cmp”, Restore these files from recycle bin. 

Now open / refresh the site in Microsoft Office SharePoint Designer 2007 and you will see all the files at the root of the site. 

The next step is to publish these files on the local folder. Right click on the files and select “Publish Selected File..” as shown in the figure below: 

7-1.jpg

“Remote Web Site Properties” dialog box will appear, select “File System” option and “Browse” to the desired local directory as shown in the figure below:  

7-2.jpg 

Click “Ok” and files will be published at the desired directory. 

Now change the extension of the files from *.cmp to *.cab and unzip to the files to a directory, say,”testdir”. (say path C:\testdir) 

Run Console and move to the bin directory of the “Microsoft Cabinet Software Development Kit”. Run the command  cabarc n test-restore.cab C:\testdir\*.* A cab file with the name test-restore.cab will be created in the bin directory of “Microsoft Cabinet Software Development Kit”. Change the extension of the file from and “*.cab” to “.cmp” and use this file to restore the site. 

In case you may encounter an error, try adding the original back up file “test.cmp” into the “testdir” directory or adding all the files from the site recycle bin into the “testdir” directory.

http://technet2.microsoft.com/Office/en-us/library/288fecfb-53fb-4988-89d7-b7888f82bf961033.mspx?mfr=true

http://www.dotnetjunkies.com/WebLog/mwherman2000/archive/2007/07/26/271409.aspx

http://support.sherweb.com/showfaq.php?idarticle=191&idcat=25

Comments (19)

MOSS: Back up and Restore Web Sites Using Microsoft Office SharePoint Designer 2007

Microsoft Office SharePoint Designer 2007 is a good resource for backup and restore. It creates a content migration package (.cmp) for the web site.

The content migration package contains library content, list content, navigation, user information, security settings, personalize settings like views and content types and customization but content migration package does not contain alerts, workflows and properties.  

BACK UP WEB SITE

The first step is open the site in Microsoft Office SharePoint Designer 2007 and move from Site menu to Administration and click on Back Web Site.  

Backup Web Site dialog box will appear which will ask to include all the sub sites in the backup, do as appropriate and click OK.  

File Save dialog box will appear, guide it to the desired location after entering the name of the .cmp file and hit OK.  

Microsoft Office SharePoint Designer 2007 will take time to crate content migration package depending upon the size of the web site.  

RESTOR WEB SITE  

First we will create an empty web site for restoring. For this, open Microsoft Office SharePoint Designer 2007 and move from File menu to New and click on Web Site. 

In the New Dialog box, select Web Site tab, then select General and then Empty Web Site. Give the desired URL  in the text box at the bottom of the dialog box and click OK. Microsoft Office SharePoint Designer 2007 will create a new empty web site.  

Now, move from Site menu to Administration and click on Restore Web Site. Browse to the desired  content migration package (.cmp file) and click OK.

This will start restoring the site and success message  will appear at the end of the process.  

Exception: 

Error occurred while exporting the web http://site URL.

Access is denied.(Eception from HRESULT:0×8007005(E_ACCESSDENIED)) 

Reason: 

You are not the administrator of the site collection. 

Resolution: 

Add yourself as site administrator. For this, open SharePoint Central Administration. Move from “Application Management” to “Site collection administrators” under  “SharePoint Site Management”. Add yourself as administrator in the appropriate site collection.

Comments (4)

In line code to upload (supportive) documents

 Recently we face a requirement from our client that one or more documents should be added against the documents already uploaded in the document library. We created a look up column (on the bases of “Title” field) and asked him to add as many documents as he wanted but he refused the solution giving two arguments. 

1-    Doesn’t have the time to go to the propertied page of each document and attach documents from there.

2-    Don’t want to fellow the process (first step was to upload the supportive document, write the name of the document in the title field and then, using properties of the target document, attach it using the look up column). 

So we have to device another solution and we decided to go in line code. For this, we added a hyperlink column and a look up column. The name of the look up column is “DocAttached”. We selected “Title” as a criteria and option for multiple values is checked. The name of the hyperlink column is “AttachDoc”. The value of the “AttachDoc” is populated by upload event handler. The code of the event handler is below: 

public override void ItemAdded(SPItemEventProperties properties)       

{           

if (properties.ListItemId.Equals(null)){   

SPListItem doc = properties.ListItem;   

doc["AttachDoc"] = “URL of the site/Upload_file.aspx?para=” + doc["ID"] + “, Attach File”;                doc.Update();           

}                   

} 

Above code concatenate the document ID with the URL of the page “Uploaded_file,aspx” that we have added using SharePoint Designer. Each time a document is uploaded, the value of the column “AttachDoc” is populated with a URL which has a concatenated value of the document ID. When the users click on the “Attach File” link provided in the “AttachDoc” column, the control passes to the page “Upload_file.aspx”.

The HTML and in line code for the page “Upload_file.aspx” is as under:   

<%@ Page Language=”C#” masterpagefile=”~masterurl/default.master” title=”|” inherits=”Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” meta:progid=”SharePoint.WebPartPage.Document” %>

<%@ Import Namespace=”Microsoft.SharePoint” %>

<asp:Content id=”Content1″ runat=”server” contentplaceholderid=”PlaceHolderMain”>

<head>

<META name=”WebPartPageExpansion” content=”full”>

<script runat=”server”>

SPSite sp;

            SPWeb WebSite;

            SPList DocLib;

int id = 0;

   

            string AddURL = “”;

string DocName = “”;

string DocTitle = “”;  

           

public void Page_Load(object o, EventArgs e)

{

           

            sp = new SPSite(”URL”);

            WebSite = sp.OpenWeb();

            DocLib = WebSite.Lists["Document Library Name"];

           

            if (string.IsNullOrEmpty(Request.QueryString["para"]))

       {

       Response.Redirect(”http://URL/Upload_error.aspx”);

       }

           

            id = Convert.ToInt32(Request.QueryString["para"]);

}

           

   

public void UploadFile(object o, EventArgs e)

{

             if (FileUpload1.HasFile)

        {

            AttachDocument(FileUpload1);           

        }

        if (FileUpload2.HasFile)

        {

            AttachDocument(FileUpload2);

        }

        if (FileUpload3.HasFile)

        {

            AttachDocument(FileUpload3);

        }

        if (FileUpload4.HasFile)

        {

            AttachDocument(FileUpload4);

        }

        if (FileUpload5.HasFile)

        {

            AttachDocument(FileUpload5);

        }       

                       

WebSite.Close();

sp.Close();

WebSite.Dispose();

sp.Dispose(); 

      

        Response.Redirect(”Document Library URL”);

}

public void AttachDocument(FileUpload file)

{

        byte[] content = new byte[file.PostedFile.ContentLength];

        string URL = “URL of the document library/” + file.FileName;

        content = file.FileBytes;

        SPFolder DocLibFolder = WebSite.GetFolder(”DLOne”);

        SPFileCollection DocLists = DocLibFolder.Files;

        sp.AllowUnsafeUpdates = true;

        WebSite.AllowUnsafeUpdates = true;

        SPFile FileAdded = DocLists.Add(URL, content);

        SPListItem DocAdded = FileAdded.Item;

        DocName = DocAdded.Name;

        DocTitle = DocName.Substring(0, DocName.IndexOf(’.'));

        DocAdded["Title"] = DocTitle;

        DocAdded.Update();

        AddURL = “;#” + DocAdded.ID + “;#” + DocTitle;

        SPView DefaultView = DocLib.DefaultView;

        SPQuery SelectQuery = new SPQuery(DefaultView);

        SelectQuery.Query = “<Where><Eq><FieldRef Name=’ID’/><Value Type=’Numeric’>” + id + “</Value></Eq></Where>”;

        SPListItemCollection SelectedDoc = DocLib.GetItems(SelectQuery);

        SPListItem doc = SelectedDoc.GetItemById(id);

        doc["DocAttached"] += AddURL;       // “;#158;#sv002″;

        doc.Update();           

}

public void button_Cancel(object o, EventArgs e)

{

  Response.Redirect(”URL of the Document Library”);

}

</script>

</head>

<body>

<div>

        <table>

            <tr>

                <td><asp:FileUpload ID=”FileUpload1″ runat=”server”/></td>

                <td> </td>

                <td> </td>

            </tr>

            <tr>

                <td><asp:FileUpload ID=”FileUpload2″ runat=”server”/></td>

                <td> </td>

                <td> </td>

            </tr>

            <tr>

                <td><asp:FileUpload ID=”FileUpload3″ runat=”server”/></td>

                <td> </td>

                <td> </td>

            </tr>

            <tr>

                <td><asp:FileUpload ID=”FileUpload4″ runat=”server”/></td>

                <td> </td>

                <td> </td>

            </tr>

            <tr>

                <td><asp:FileUpload ID=”FileUpload5″ runat=”server”/></td>

                <td> </td>

                <td> </td>

            </tr>

            <tr>

                        <td>             </td>

            </tr>

            <tr>

             <td><asp:Button ID=”Button2″ runat=”server” Text=”Upload” OnClick=”UploadFile”/>

                <asp:Button ID=”Button1″ runat=”server” Text=”Cancel” OnClick=”button_Cancel”/></td>

                <td>                   

                </td>

            </tr>

        </table>   

    </div> 

</body>                                              

</asp:Content>

 

The screen shoot of the “Upload_file.aspx” is as under: 

 

5-1.jpg

Comments (2)

Code Behind in MOSS

Code Behind in MOSS  This is great to be able to use ASP.Net code behind model for coding in MOSS. This adds great flexibility in writing customized code for MOSS. Let’s start doing this. 

The first step is to create a Web site project in Visual Studio. The details of the files are as under: Hello.aspx

 <%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Hello.aspx.cs” Inherits=”HelloNameSpace.HelloClass” %> 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> 

<html xmlns=”http://www.w3.org/1999/xhtml” >

<head runat=”server”>

<title>Code Behind Example for MOSS</title>

</head>

<body>   

<form id=”form1″ runat=”server”>   

<div>       

<asp:Button ID=”Button1″ runat=”server” Text=”Click Me” OnClick=”Button1_Click” />   

</div>   

</form>

</body>

</html>  

Hello.aspx.cs 

namespace HelloNameSpace{   

public partial class HelloClass : System.Web.UI.Page    {       

protected void Button1_Click(object sender, EventArgs e)        {           

Response.Write(“HELLO WORLD.”);       

}   

}

} 

The next step is to generate a strong name key. We can use the tool “Sn.exe”. The path, where it can be found, is “C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin”. Use the following command to generate the key. 

sn –k HelloNameSpace.snk 

The next step is to publish the site. For this, right click on the project and select “Publish Web Site”. This will generate a new window as shown in the figure below:  

4-1.jpg 

Check the option “Enable strong naming on precompiled assemblies” and gave the path of the file “HelloNameSpace.snk” that you created just before. 

Click “OK” and publishing will be succeeded.  

Go to the bin directory of the Visual Studio solution and copy the DLL file from the bin directory of the solution to the bin directory of the SharePoint site. The path of the bin directory of SharePoint can be “C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin”. Also, copy the name of the DLL file. In our case it is “App_Web_js_i-de4.dll”.

Now, its time to add the code in the MOSS site. Open the site in the SharePoint Designer and add a aspx page in the site.  

Copy and past the HTML from the file “Hello.aspx” into the aspx page added in the SharePoint Designer. Don’t forget to change the first line of the code as under: 

<%@ Page Language=”C#” AutoEventWireup=”true” Inherits=”HelloNameSpace.HelloClass, App_Web_js_i-de4″ %> 

Next step is to add two entries in the web.config file accordingly 

<SafeControl Assembly=App_Web_js_i-de4 Namespace=SPCodeBehind TypeName=* Safe=True /> 

And 

<PageParserPaths>        <PageParserPath VirtualPath=/* CompilationMode=Always AllowServerSideScript=true IncludeSubFolders=true />      </PageParserPaths> 

It is strongly recommended that you should save a copy of web.config file before making changes. The file web.config can be found at “C:\Inetpub\wwwroot\wss\VirtualDirectories\80”. 

Now access the page and hopefully it will work fine. 

The problem with this approach is that you can’t make changes in case you want to inherit master page, it will generate exception.  

For more help, follow the link below

http://blogs.vertigo.com/personal/willa/Blog/Lists/Posts/Post.aspx?ID=4

http://msdn2.microsoft.com/en-us/library/bb892187.aspx

Comments

In line code for MOSS

In line Code for MOSS

Adding in line code is tricky. Microsoft support policies recommended for inline code are as under: 

Inline code in Site Definition based ASPX pages:

Inline code is not recommended within a site definition due to the issues involved with the code no longer rendering as soon as the page is customized. 

Inline code in _layouts-based ASPX pages:

Inline code is supportable if included on a page in the _layouts directory. 

Inline code enabled through PageParserPath exclusion:

Inline code should not be allowed through the PageParserPath exclusion, except in extremely rare circumstances, because it can be modified without going through any review process. As a result, it represents a danger to the environment’s performance and security. 

So think about the pros and cons and if you are still ready to take the ride, continue reading. The first step is to open the site in Microsoft Office SharePoint Designer.  

Go from File -> New -> Page and select ASP.Net under “Page” and then select “Create from Master Page..”. You can add any page depending upon your requirements. 

This will open a blank page which will inherit master page look & feel. Now add you script under first head tag. If you don’t find it, add the head tag as well. The code written by me is as under: 

<head>

<META name=”WebPartPageExpansion” content=”full”>

<script runat=”server”>        

 SPSite sp;       

SPWeb WebSite;       

SPList DocLib;       

public void Page_Load(object o, EventArgs e){                

sp = new SPSite(”Site URL”);       

WebSite = sp.OpenWeb();       

DocLib = WebSite.Lists["Doc Library Name"];       

} 

public void Hello_Click(object o, EventArgs e){       

context.Response.Write(“HELLO WORLD”);

} 

</script>  

</head>             

Add the method on the OnClick event of the button. Lastly, make changes in the web.config file. Usually present at this path C:\Inetpub\wwwroot\wss\VirtualDirectories\80.

But before making changes, save the file at some other place or you might be in big trouble. Add the following line in the PageParserPaths. Be careful.  

<PageParserPaths>       

<PageParserPath VirtualPath=”/*” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders=”true” />     

</PageParserPaths>

</PageParserPaths> 

Save the changes and access the page in the browser. 

Exception: 

An error occurred during the compilation of the requested file, or one of its dependencies. The type or namespace name ‘SPSite’ could not be found (are you missing a using directive or an assembly reference?) 

Reason: 

Forget to import SharePoint namespace. 

Resolution: 

Add <%@ Import Namespace=”Microsoft.SharePoint” %> after the page directive. 

Exception: 

An error occurred during the compilation of the requested file, or one of its dependencies. Invalid token ‘=’ in class, struct, or interface member declaration 

Reason: 

Didn’t initialize variables in Page_Load method. 

Resolution: 

Initialize variables in Page_Load method.

Comments (1)