How to hide user name in Sharepoint Survey?

By Namwar Rizvi - Last updated: Tuesday, January 20, 2009

If you want to hide the identity of the user who responded your survey, just perform the following steps:

  1. Navigate to your survey page
  2. Click Settings and then click Survey Settings
  3. survey-settings

  4. Under General Settings click Title, description and navigation link
  5. general-settings

  6. Under Survey Options, select No for the question Show user names in survey results?
  7. show-user-names

  8. Click Save

Now, check your survey and you will see that all user identity fields like Created By and Last Modified By will just show *** instead of the original user name.

Share
Filed in Management • Tags: , ,

How Sharepoint ranks a document in Search Results?

By Namwar Rizvi - Last updated: Monday, January 12, 2009

Several times I have been asked about the way Sharepoint calculates the rank of a document in document search. Although, it is based on a complex probablistic algorithm developed by Microsft Researcher, following are some simple tips to know the background of search ranking and how to tune the search results. Please note, these tips are not an authentic statements from Microsoft, instead they are my observations and knowledge gained from other fellow Sharepoint experts.

According to Microsoft on Technet in this article

Ranking depends on:

Keeping the above points in mind, following observations have been made as mentioned in this blog

Share
Filed in Architecture, SSP • Tags: , ,

How to solve "Unable to connect publishing custom string handler for output caching"

By Namwar Rizvi - Last updated: Sunday, January 11, 2009

If you are getting “Unable to connect publishing custom string handler for output caching” error in your event log then it is because of a custom web service you have installed on your Sharepoint server. Reason for this error is that you have a web part on your portal page which use the custom web service. Now, since Sharepoint uses output caching for the web pages to optimize the rendering experience and fast delivery of unchanged pages therefore, publishing infrastructure of Sharepoint tries to access the web service through your web part and due to any issue in your service, it starts generating this error.

Anyway, cutting a long story short, here is the solution:

Edit the web.config of custom web service (Please do not edit your Sharepoint Web application web.config) and make sure you have following under httpModules node which is located under system.web node. 

            <remove name=PublishingHttpModule />



Share
Filed in Errors, Management • Tags: , , ,

Programmatically upload a file to Document Library

By Namwar Rizvi - Last updated: Saturday, January 10, 2009

Following is a utility function which you can use to upload a file programmatically in SharePoint document library. It has two parameters. First is the source file path and second is the target document library path. 

Following is an example call to this function:

UploadFileToDocumentLibrary(@”C:\test.txt”, @”http://home-vs/Shared Documents/textfile.txt”);

and here is the function

    public static bool UploadFileToDocumentLibrary(string sourceFilePath, string targetDocumentLibraryPath)

    {

        //Flag to indicate whether file was uploaded successfuly or not

        bool isUploaded = true;

        try

        {

            // Create a PUT Web request to upload the file.

            WebRequest request = WebRequest.Create(targetDocumentLibraryPath);

 

            //Set credentials of the current security context

            request.Credentials = CredentialCache.DefaultCredentials;

            request.Method = “PUT”;

 

            // Create buffer to transfer file

            byte[] fileBuffer = new byte[1024];

 

            // Write the contents of the local file to the request stream.

            using (Stream stream = request.GetRequestStream())

            {

                //Load the content from local file to stream

                using (FileStream fsWorkbook = File.Open(sourceFilePath, FileMode.Open, FileAccess.Read))

                {

                    //Get the start point

                    int startBuffer = fsWorkbook.Read(fileBuffer, 0, fileBuffer.Length);

                    for (int i = startBuffer; i > 0; i = fsWorkbook.Read(fileBuffer, 0, fileBuffer.Length))

                    {

                        stream.Write(fileBuffer, 0, i);

                    }

 

                }

            }

 

            // Perform the PUT request

            WebResponse response = request.GetResponse();

 

            //Close response

            response.Close();

        }

        catch (Exception ex)

        {

            //Set the flag to indiacte failure in uploading

            isUploaded = false;

        }

 

        //Return the final upload status

        return isUploaded;

    }

Share
Filed in C# • Tags: ,

How to debug custom application pages in Sharepoint

By Namwar Rizvi - Last updated: Friday, January 9, 2009

To debug your custom application pages located in layouts folder, perform the following steps:

  1. In IIS, select your web application and from context menu, select Open. It will display the directory in windows explorer
  2. Edit Web.config in any text editor (e.g. Notepad)
  3. In web.config, search for compilation node like “<compilation batch=”
  4. To enable debugging, update the node as follows
    • Set batch=false
    • Set debug=true
  5. After update, your compilation node will become <!– /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:””; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:”Times New Roman”; mso-fareast-font-family:”Times New Roman”;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} –>

    <compilation batch=false debug=false>

  6. Launch Internet Explorer and browse your custom application page
  7. Now, launch Visual Studio and open your Custom Application Page from layouts directory
  8. Go to Debug->Attach To Process and attach to w3wp.exe
  9. attachtoprocess1
    attachtoprocess2

  10. Add break points as necessary.
  11. In Internet Explorer, refresh your page and bingo! you can debug your custom application page now.
Share
Filed in Debugging

SQL Server 2005 Service Pack 3 and Sharepoint 2007

By Namwar Rizvi - Last updated: Thursday, January 1, 2009

If you are using Sharepoint 2007 to manage and display your reports then there is a big chance you may be using Reporting Services in Sharepoint Integrated mode. You may have noticed that reports run slower in Sharepoint integrated mode as compared to native mode. This is because of the calls to Sharepoint object model in integrated mode. To improve the performace Microsoft has released some optimizations in Service Pack 3 of SQL Server 2005 which reduces the number of calls to object model and increases the overall response  time and performace.

Happy New Year to all readers and best wishes for 2009!

Share
Filed in Uncategorized • Tags: , ,

List of SharePoint URL tokens

By Namwar Rizvi - Last updated: Monday, December 1, 2008

Following is a list of tokens available in Sharepoint to use in your URLs. Be aware that Sharepoint only replaces the value of a token once for a given string, so if you have used the same token twice, second occurance will not be replaced by the token value. I will post a solution to do it in my next article:

~site – Web site (SPWeb) relative link.

~sitecollection – site collection (SPSite) relative link.

In addition, you can use the following tokens within a URL:

{ItemId} – Integer ID that represents the item within a list.

{ItemUrl} – URL of the item being acted upon. Only work for documents in libraries. [Not functional in Beta 2]

{ListId} – GUID that represents the list.

{SiteUrl} – URL of the Web site (SPWeb).

{RecurrenceId} – Recurrence index. This token is not supported for use in the context menus of list items.

Share
Filed in Architecture, Customization • Tags: ,

Sharepoint Patterns and Practices

By Namwar Rizvi - Last updated: Monday, November 10, 2008

If you are looking for standard patterns and practices used for Sharepoint Platform then look no further.

Microsoft has released an excellent guidance package for Sharepoint Developers and Architects. You can download it from the following URL

http://www.microsoft.com/downloads/details.aspx?familyid=c3722dba-6ee7-4e0e-82b5-fdaf3c5ec927&displaylang=en&tm

I will recommend every reader to download it and check it as it has lot of information. Some of the highlights are (as per Microsoft description)

This guidance helps architects and developers build SharePoint intranet applications. A reference implementation (RI) demonstrates solutions to common architectural, development and lifecycle management challenges.
This guidance discusses the following:

The following areas are not discussed in this version of the guidance:

Share
Filed in Guidance • Tags:

How to display real Error in Sharepoint web site

By Namwar Rizvi - Last updated: Saturday, October 25, 2008

Just perform the following steps to display the real error happened in Sharepoint site instead of a generice Unknow error message.

  1. Backup your web.config of web application
  2. In SafeMode tag under SharePoint change 

              CallStack=”true

              MaxControls=”200

After changing, your SafeMode node will be similar to following

<SafeMode MaxControls=”200″ CallStack=”true” DirectFileDependencies=”10″ TotalFileDependencies=”50″ AllowPageLevelTrace=”false”>

3.  Set  customErrors mode=”Off

 

 

Share
Filed in Configuration, Debugging • Tags: ,

How to fix Script Error in Web File Properties: length' is null or not an object?

By Namwar Rizvi - Last updated: Thursday, October 23, 2008

If you are getting a weired script error “length is null or not an object” while saving the documents from Microsoft Office word, excel etc. then you are not alone:):)

This behaviour occurs without any obvious reason and has been identified as a bug by Microsoft. After wasting a lot of time, I was able to found the hotfix released from Microsoft at

http://support.microsoft.com/default.aspx?scid=kb;EN-US;950292

Please install this hotfix at your own risk and make sure you have taken the backup of your servers before applying this hotfix.

Please post comments and experiences for this bug.

Share
Filed in Bugs • Tags: , , , ,