Showing posts with label 2007. Show all posts
Showing posts with label 2007. Show all posts

Friday, August 16, 2013

SharePoint Migration Utilities

When I Migrated or revamped SharePoint I need to do some tasks help migrate old items, alerts, etc with new structure. I wroted some utilities to do these tasks using SharePoint API. I know there is many tools can do these tasks but here will find free utilities to do simple tasks.
Copy Files
Copy list Document libraries  and mapped old properties to new properties.

Copy Alerts
Copy Alerts from source web to destination Web

Copy Images
Copy Images from source image library to destination image library

Copy List Items
Copy List Items from source list to destination list

Copy Pages with resources
Copy Publish Pages between source and destination, Update layouts, clean HTML

Copy SharePoint Security
Copy Security between source and destination list.

Jungle.SharePoint.Util
Utilities help in migration tasks






Wednesday, August 8, 2012

DataView Asynchronous Paging issue

I faced problem when tried to use paging with DataView. Because DataView use history.back(); for previous link. It doesn't work correct.
I found  blog solved this problem:
http://geekswithblogs.net/haniamr/archive/2011/05/31/paging-problem-in-data-form-webpart-sp2010.aspx

Open the code view and search for a that has a class named “ms-paging” and then paste those lines before the starting of the td tag:

<xsl:variable name="dvt_PrevPageData">
<xsl:choose>
<xsl:when test="($FirstRow - $RowLimit - 1) > -1">
<xsl:value-of select="$FirstRow - $RowLimit - 1" />
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>

• Search for “history.back()” and then replace the line with that line:
<xsl:attribute name="href">javascript: <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={',$PrevRow,'};dvt_startposition={Paged=TRUE&p_ID=',$dvt_PrevPageData,'}'))" />;</xsl:attribute>

To make sure this solution work correct RowLimit must equal pagesize

Sunday, July 1, 2012

List.Items.Count Vs List.ItemCount

The value of the ItemCount property includes folders within a document library, as well as files within subfolders.
The value of the Count property of the SPListCollection class does not include folders.

Checklist for Creating SharePoint Web Parts

To find a checklist contains a series of tasks designed to help you determine the quality of Web Parts you are asked to deploy or maintain, Check this link:
http://msdn.microsoft.com/en-us/library/bb985502%28v=office.12%29.aspx

Open SharePoint management forms in new page

If you want to open SharePoint Form in new page instead of popup:
  1. Right Click in popup page and copy the url.
  2. Remove IsDlg=true from query string.
  3. You need yo modify return url adjust root folder and source url.

    Url will be as below:
    /news/_layouts/SubNew.aspx?List={B2AE3C44-1965-447F-BFEF-D87706BE51DD}&RootFolder=&source=/

SharePoint Plan browser support

These articles describe different levels of Web browser support
Office SharePoint Server 2007:
http://technet.microsoft.com/en-us/library/cc263526%28v=office.12%29.aspx

SharePoint Server 2010:
http://technet.microsoft.com/en-us/library/cc263526.aspx

Monday, June 11, 2012

SharePoint Batch Insert/Update/Delete Performance

When you want to do bulk transaction insert, update, or delete.
If you have to update a larger number of items its highly recommended to not use the Update method on every item. Instead – use the batch update function ProcessBatchData provided by SPWeb.

StringBuilder query = new StringBuilder();
for (int itemIx=0;itemIx<100;itemIx++) {
  query.AppendFormat("" +
          "{1}" +
          "New" +
          "Save" +
          "{2}" +
       "", i, listGuid, someValue, "urn:schemas-microsoft-com:office:office#");
}
SPContext.Current.Web.ProcessBatchData("" +
    "{0}", query.ToString())

For more details of using ProcessBatchData check url:
http://stefan-stanev-sharepoint-blog.blogspot.com/2009/07/tips-for-using-spwebprocessbatchdata.html


Adding XsltListViewWebPart to sitedefinitions

If you want to add XsltListViewWebPart with custom xslt to site definition:
  1. Create a web part and do all configuration in existing site. Then export the web part this web part need some modifications to add to site definition.
  2. Exported Web Part contains ListGuid Which is difference from site to other. Remove ListGuid. Add one from these properties  ListName, ListUrl, or ListDisplayName
    One of the List* properties (ListName, ListUrl, or ListDisplayName) must be present and must specify a reference to a valid list. If more than one property is present, the order of evaluation is ListName, then ListUrl, and then ListDisplayName.
 

Add SPNavigation Heading programmatically

If you want to add header without link to SharePoint Navigation pro-grammatically,  Need to set some values in the NavigationNode.Properties HashTable.


            SPNavigationNode node, node1;
            // Get the parent’s top link bar.
            SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;

            // Create the node.
            node = new SPNavigationNode("News", "/news", true);
            topnav.AddAsLast(node);

            node = new SPNavigationNode("Services", string.Empty, true);
            node = topnav.AddAsLast(node);
            node.MakeHeaderNode();
            node1 = new SPNavigationNode("IT Support", "/Services/Lists/Helpdesk Initiation/NewForm.aspx?RootFolder=&source=/", true);
            node.Children.AddAsLast(node1);


public static class SPNavigationNodeExtensions
{
    public static void MakeHeaderNode(this SPNavigationNode node)
    {
        node.Properties["BlankUrl"] = "True";
        node.Properties["LastModifiedDate"] = DateTime.Now;
        node.Properties["Target"] = "";
        node.Properties["vti_navsequencechild"] = "true";
        node.Properties["UrlQueryString"] = "";
        node.Properties["CreatedDate"] = DateTime.Now;
        node.Properties["Description"] = "";
        node.Properties["UrlFragment"] = "";
        node.Properties["NodeType"] = "Heading";
        node.Properties["Audience"] = "";
        node.Update();
    }
}
As you can see, the “BlankUrl'” = True, and NodeType = “Heading”.

Sunday, June 10, 2012

Update PublishingImages using list.asmx

It takes from me too long time before success update PublishingImage Column using list.asmx.
We should pass value relative url with alt separated by comma. This is also applied for url, lookup, or user.
Check example below:
 string xml = ""+
        ""+
        "    1"+
        "    http://www.pub.com/publishingimages/test.jpg, test"+
       
"+

"       ";

Friday, June 1, 2012

Access WebParts using HttpContext from Console Application

I Created Console Application to export WebParts from SharePoint but I faced problem with web parts used HttpContext like CQWP (With Console Application HttpContext.Current is null). I cannot read web part properties. After some investigation I found the solution create a dummy HttpContext with the following code:


  if (HttpContext.Current == null) {
      HttpRequest request = new HttpRequest("", web.Url, "");
      HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));
      HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
  }

Don't forget to set HttpContext.Current to null after finishing.
Now I can access web parts from console application.

Tuesday, May 8, 2012

SharePoint Best Practices when use object model

When we run SharePoint Site Without any code customization we will notice big difference in performance. There are many common things affect performance with object model:

  • Dispose SharePoint Objects:
    SharePoint object model contains objects that implement the IDisposable interface. You must take precautions when using these objects to avoid their long-term retention in memory in the Microsoft .NET Framework.
    Specifically, you should explicitly dispose of those SharePoint objects that implement IDisposable when you are finished using them.
    The following unusual behaviors occurred when you did not disposing of SharePoint objects when you are finished with them

    1. Frequent recycles of the Windows SharePoint Services application pool, especially during peak usage.
    2.  Application crashes that appear as heap corruption in the debugger.
    3.  High memory use for Microsoft Internet Information Services (IIS) worker processes.
    4. Poor system and application performance.

    There are 2 articles contains best practice for disposing objects:
    http://msdn.microsoft.com/en-us/library/ee557362.aspx

    http://blogs.msdn.com/b/rogerla/archive/2009/11/30/sharepoint-2007-2010-do-not-dispose-guidance-spdisposecheck.aspx

You can use SharePoint Dispose Checker Tool:
This tool helps developers and administrators check custom SharePoint solutions that use the SharePoint Object Model helping measure against known Microsoft dispose best practices.
http://archive.msdn.microsoft.com/SPDisposeCheck

  • Using SharePoint Data and Objects Efficiently

    1. Caching Data and Objects 
    2. Using Objects in Event Receivers
    3. Working with Folders and Lists
    4. Deleting Multiple Versions of a List Item
    5. Writing Applications That Scale to Large Numbers of Users

    There is article take about Common Coding Issues When Using the SharePoint Object Model:  http://msdn.microsoft.com/en-us/library/bb687949%28v=office.12%29.aspx
  • Decrease round trips with the database:|
    When you access SharePoint using object model every time access . retrieve data from the database for example:
    If we loop over list items like:
    for(int i=0;i&lt;web.list["News"].Items.Count;i++)         
    {
          SPListItem item = web.list["News"].Items[i];
    }

    The best practice assign SharePoint Objects in variables and use these variable:
    SPList list = web.list["News"];
    SPListItemCollection itemCol= list.Items;                       
    for(int i=0;i&lt;itemCol.Count;i++)
    {
          SPListItem item = itemCol[i];
    }
    This role must be applied in most objects of SharePoint.
I found good engine called FASTSPWeb in codeplex help you to solve some problems:
  • Decrease database round trip by caching SharePoint objects automatically in the web application process and allowing multithreaded access to these objects.
  • Correct disposing of opened SPWeb and SPSite object is also not an issue because FASPSPWeb is handling all instantiating and disposing automatically.
This tool link is:
http://fastspweb.codeplex.com/