Archive

Posts Tagged ‘sharepoint errors’

Ensure trailing slash

Sometimes you don’t know if you’ll get a trailing slash or not with a web.Url or site.Url. Use the method:

public static string EnsureTrailingSlash(string strUrl)
        {
            if (!strUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                strUrl += "/";
            }
            return strUrl;
        }

Call like this:
SharedUrlUtility.EnsureTrailingSlash(SharedUserProfiles.MySiteHostUrl);

Hope this helps-
Rehman.

Advertisements

Error: cannot connect to performancepoint services

August 4, 2011 2 comments

Here is what worked for me:

Go to Central Admin > Application Management > Configure service application associations > click default.

You should see that PerformancePoint Services will be unchecked. Check that box and you should be good to go.

Hope this helps–
Rehman.

Performance Point – “Code blocks are not allowed”

When you try to launch performance point designer you get “An error occurred during the processing of /mysitecollection/pages/ppssample.aspx. Code blocks are not allowed in this file” ….

Go to your web.config and add the following:

<PageParserPaths>
	<PageParserPath VirtualPath="/mysitecollection/Pages/ppssample.aspx" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>

Hope this helps–
Rehman.

Javascript from within CSharp

This is how you can write javascript from within c#:

if (dtStart.SelectedDate != dtEnd.SelectedDate)
			{
			    Response.Write(@"<script language='javascript'>alert('Start date must be equal to end date. Only hours and minutes can be different.');</script>");
			}

Hope this helps-
Rehman.

SharePoint Designer Workflow is not updated

October 20, 2010 4 comments

So, you are making changes to your SPD workflow and they are not reflected on the list/doc library where the workflow is deployed.

Sometimes, SPD will use the cahced information from a location such as the following:

%System Drive%\Documents and Settings\%user%\Local Settings\Application Data\Microsoft\WebSiteCache

Here you will find a folder named similar to your SharePoint site on which you are working. Usually its the server name concatenated with the port on which your SharePoint site is running e.g. MySharePointServer8080.

Delete this folder and restart SharePoint Designer and you should be good to go. Make any changes to your workflow and they should be reflected onto your list/library.

Hope this helps–
Rehman.

COM exception while adding item to Document Library

October 20, 2010 6 comments

What I was doing:
I created a SharePoint Designer workflow that will run automatically as soon as an item is added into the document library. It will simply add some metadata to the item.

What happened:
When you add an item to a document library, it will upload the document and then redirect you to EditForm.aspx where you can edit metadata for the document. On this form when I clicked “OK”, I received the following exception:

Microsoft.SharePoint.SPException: The file Shared Documents/Test.doc has been modified by Sydney\rehman on 20 Oct 2010 16:51:42 +1000. ---> System.Runtime.InteropServices.COMException (0x81020037): The file Shared Documents/Test.doc has been modified by Sydney\rehman on 20 Oct 2010 16:51:42 +1000.

Why it happened:
As soon as the document was uploaded, my SPD workflow went in and updated the metadata on the document (as it is configured to run automatically on the creation of the item). Now I am redirected to EditForm.aspx to edit metadata on the document. Here, even if I modify nothing and click “OK”, the COM Exception is generated, since the document metadata is already modified by the workflow and this is not liked by SharePoint. My clicking “OK” means I am trying to update/modify a previous version of this document. The current version is the one modified by my workflow. Hence the error: “Document has been modified by so and so……..”. If you want to edit, go and edit the current version from the document library. Here, on EditForm.aspx, if you click “Cancel”, you can see that document has actually been modified and has the metadata attached as a result of the workflow execution. (Ofcourse, it is already uploaded to the doc lib, clicking cancel on EditForm.aspx doesnt stop it.)

What I did to resolve:
Mine is just a workaround, its not a proper solution to the problem. I simply forced a redirect to AllItems.aspx page i.e. as soon as the document is uploaded, the page will not redirect to EditForm.aspx, it will be redirected to AllItems.aspx…………so the user will not get an option to edit metadata on the document and click “OK” (due to which the error is generated).

I didnt use pause in the workflow because it takes too long and if the user clicks okey during that pause, which is most likely, he wont see the metadata that should have been attached by my workflow, and this will freak him out, in my case the user must see that metadata on the document.

so I added simple javascript on EditForm.aspx, which will redirect the user to AllItems.aspx when the Mode is equal to Upload……………..this is important. We dont want to redirect when the user is just going to EditFrom.aspx by clicking Edit Properties from the context menu of the item. Have a look at the javascript:

Put this code on line 71 of the EditForm.aspx of your document library.


<script language="javascript" type="text/javascript">
    _spBodyOnLoadFunctionNames.push("Redirect");
    function Redirect() 
    {
       var mode = getURLParam('Mode');
       var sourceURL = getURLParam('Source');
       var  properSourceURL = replaceCharacters(sourceURL);
       if (mode == "Upload")
          window.location = properSourceURL;    	   
	 }
    
    function getURLParam(name)
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
	    return "";
	  else
	    return results[1];
	}
	
	function replaceCharacters(str)
	{
	   str = str.replace(/%20/g, " ");
	   str = str.replace(/%2F/g, "/");
	   str = str.replace(/%3A/g, ":");
	   str = str.replace(/%2E/g, ".");
	   return str;	  
	}

Following is the URL on the EditForm.aspx when redirected from an upload page:

http://sydtelfev02:8989/Documents/Forms/EditForm.aspx?Mode=Upload&CheckInComment=&ID=78&RootFolder=%2FDocuments&Source=http%3A%2F%2Fsydtelfev02%3A8989%2FDocuments%2FForms%2FAllItems%2Easpx

So, you can see there are two parameters in the URL:

1. Mode
2. Source

My code simply checks if the Mode is equal to Upload, then redirect to the URL as mentioned by the Source parameter. In the Source parameter, the given URL is in quite a distorted format, so I have written some additional javascript to replace weird characters and codes in the URL with proper ones like “:” “/” and “.” etc.

Hope this helps–
Rehman.

Calculated Field to set a Due Date

September 30, 2010 Leave a comment


=DATE(YEAR(Today),MONTH(Today),DAY(Today)+14)

As you might know calculated fields or calculated values cannot have volatile funcs like [TODAY] or [ME]……

so to use above formula, first create a column named Today (cud be single line of text or anything and no need for any default value, just create this column).

then create ur calculated field or Date and Time field and put the calculated value as above formula………

The above formula will add 14 days to the current day…….so what ever is due date, you can use this formula to calculate it….

Note: In date and time fields, you can directly set calculated values, no need to create a calculated column.

Hope this helps–
Rehman.