Archive

Posts Tagged ‘fix’

Format Date and Time

Format date and time :

m_CalculatedOutOfOfficeStartDate = outOfOfficeStartDate.ToString("dd/MM/yyyy");
m_CalculatedOutOfOfficeEndDate = outOfOfficeEndDate.ToString("dd/MM/yyyy");

Hope this helps-
Rehman.

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.

Viewstate error on sharepoint custom page

March 2, 2011 2 comments

Created a custom aspx form in my sharepoint application. Put that under layouts folder. Placed a gridview control on it and started receiving the following error:


Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)    at System.Web.UI.Control.AddedControl(Control control, Int32 index)    at xxxxx.SharePoint.EventsMgmt.BookingForm.RenderSearchResults(DataTable roomAvailabilityTable)    at Telstra.SharePoint.EventsMgmt.BookingForm.OnClickOK(Object Sender, EventArgs e)    at System.Web.UI.WebControls.Button.OnClick(EventArgs e)    at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Solution:

Set enableViewState=false in gridview tag on the aspx page…….(not code behind). solved the problem.

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.

Filter Views based on a Week

October 6, 2010 2 comments

Following post will help you filter views for Current Week items, Previous All Week(s) items and Next All Week(s) items.

Create a “WeekStart” calculated column.

Use the following formula and replace “Week Commencing” with the date you want to use in the formula e.g. Created etc.

Also, select “Date and Time” as a datatype returned by the formula.


=IF(TEXT(WEEKDAY([Week Commencing]),"ddd")="Mon",[Week Commencing],IF(TEXT(WEEKDAY([Week
Commencing]-1),"ddd")="Mon",[Week Commencing]-1,IF(TEXT(WEEKDAY([Week Commencing]-2),"ddd")="Mon",[Week

Commencing]-2,IF(TEXT(WEEKDAY([Week Commencing]-3),"ddd")="Mon",[Week

Commencing]-3,IF(TEXT(WEEKDAY([Week Commencing]-4),"ddd")="Mon",[Week

Commencing]-4,IF(TEXT(WEEKDAY([Week Commencing]-5),"ddd")="Mon",[Week Commencing]-5,[Week

Commencing]-6))))))

Create a “WeekEnd” calculated column.

Use the following formula and replace “Week Commencing” with the date you want to use in the formula e.g. Created etc.

Also, select “Date and Time” as a datatype returned by the formula.


=IF(TEXT(WEEKDAY([Week Commencing]),"ddd")="Sun",[Week Commencing],IF(TEXT(WEEKDAY([Week
Commencing]+1),"ddd")="Sun",[Week Commencing]+1,IF(TEXT(WEEKDAY([Week Commencing]+2),"ddd")="Sun",[Week
Commencing]+2,IF(TEXT(WEEKDAY([Week Commencing]+3),"ddd")="Sun",[Week

Commencing]+3,IF(TEXT(WEEKDAY([Week Commencing]+4),"ddd")="Sun",[Week

Commencing]+4,IF(TEXT(WEEKDAY([Week Commencing]+5),"ddd")="Sun",[Week Commencing]+5,[Week

Commencing]+6))))))

Now Create Views:

Items from Current Week only:

WeekStart<=[Today] AND WeekEnd>=[Today]

Items from Next Week(s) only:

WeekStart>=[Today]

Items from Previous Week(s) only:

WeekStart>=[Today] OR WeekEnd<=[Today] AND WeekStart<=[Today]

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.