Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Friday, May 10, 2013

Adding your own links to SharePoint 2013 suite bar


Adding your own links to SharePoint 2013 suite bar

Thursday, January 10, 2013

Sharepoint Fault Handler in vs 2008

Please see  Sharepoint Fault Handler in vs 2008

Also below is a copy.

Fault Handler
To get more detailed information about this error, it is necessary to add a Fault Activity (equivalent of a catch block) and to log it.
Select the workflow in the (Visual Studio) Workflow Designer, click on the lower left side of the Designer and click on the Fault Handler:
image
Another view of the Workflow Designer will show up:
image
Drag and drop a FaultHandler activity from the Workflow Foundation toolbox into  fautlHandlersActivity1 :
image
In the property page of this last activity select the FaultType property by browsing the mscrolib assembly:
image
Select System.Exception:
image
Now we will log the StackTrace into the workflow history log: drag and drop a LogHistoryList activity into the handler (if you don’t find this activity drag and drop the microsoft.Sharepoint.WorkflowAction.dll assembly to a new Visual Studio toolbox tab) :
image
Select the logToHistoryListActivity1 and set its HistoryOutcome property to the stack trace value of faultHandlerActivity1:
image
image
Rebuild the solution , redeploy (install.bat) and test the workflow.
The trace will show up in the workflow status :
image

Tuesday, December 18, 2012

Controls on the InfoPath Task Edit Form Not Persisting Values

The SharePoint 2010 Visual Studio workflow uses an InfoPath form as the task edit form. On the form, values of some of the controls are persisted once the task edit form is submitted, but values of some other ones are not. For instance, input a value into a textbox then submit the task edit form, then open the task edit form again, the textbox is empty, the inputted value is gone.

It turns out that the problem is caused by the column name of the task list of the workflow. Let's say there is a textbox on the InfoPath task edit form, the textbox is bound to ClientName field and default value for ClientName field is ows_ClientName via the ItemMetadata.xml file. If the workflow task list has a column named ClientName, then the value of the textbox is not persisted. For unknown reason, the workflow engine can't process ExtendedProperties["ClientName"] correctly.

Solution: The column name of the workflow task list should not be the same name from ItemMetadata.xml file, without the ows_ prefix, if the value of the control bound to the entry in ItemMetadata.xml file needs to be persisted.

How to retrieve a reference to the SearchServiceApplicationProxy

Excerpt from this page:
http://dotnetmafia.sys-con.com/node/1498722/mobile

I think the new best practice will be to pass a reference to the SearchServiceApplicationProxy.  The trick of course is getting that reference.  First, you need to determine the name of your Search Service Application.  For a typical Enterprise Search installation it is called Search Service Application.  However, it can be called anything depending on how you configured SharePoint.  For FAST, it might be called something like FAST Content SSA.  Go to Central Administration –> Service Applications and take a look.
SearchServiceApplicationAndProxy
The proxy will usually have the same name as the Service Application, so in my case here the name of my proxy is Search Service Application.  Now we just can’t get a reference to the SearchServiceApplicationProxy directly.  We have to go through the SearchQueryAndSiteSettingsServiceProxy class first.  According to the SDK, the function of going through this service is to ensure queries are load balanced.  Here is how you get a reference to the query and settings proxy.  It also assumes this code is executing on one of the servers in the farm.
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
Now that we have a reference to the settings proxy, we can get a reference to the SearchServiceApplicationProxy with the name of the proxy that we saw above.  Change the name to match whatever yours is called.
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("Search Service Application");


Now you can pass this proxy to the constructor of the KeywordQuery or FullTextSqlQuery.

Wednesday, March 28, 2012

SetState activity fails using one of the predefined SPWorkflowStatus enumeration values

Get the following error message: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.     at Microsoft.SharePoint.Workflow.SPWorkflow.SetIStatus(Int32 i, Int32 iStatus)

Workaround: use custom values, see below:

<ExtendedStatusColumnValues>
<StatusColumnValue>CustomStatusStatusColumnValue>
ExtendedStatusColumnValues>

Thursday, March 22, 2012

How to change the namespace of safecontrol entry for a visual webpart

Here it is: basically you need to make the change in SharePointProjectItem.spdata which is located at the same folder as your webpart code.


I found the solution from this blog: http://pholpar.wordpress.com/2010/03/10/changing-the-namespace-of-the-web-part-in-a-visual-web-part-project/

Wednesday, July 20, 2011

"relative links" Error when verifying/uploading infopath 2010 form template

Got the following error message when trying to deploy an infopath 2010 form template with code via central administration to production:

“Relative links to Data Connection Libraries located in different SharePoint Site Collections are not supported.”


Google search found the following blog 

Relative Links” Error Message when verifying an InfoPath Form Template by Rob Finney

In summary, the url to the SharePoint site needs to be exactly the same, including upper/lower cases, in the data connection settings. So to fix, just delete the offending data connection, add it back, then convert it to data collection file, at this step, ensure the url is correct and the capitalization of each letter is exact the same as the other data connections.


Monday, March 14, 2011

Delete All Items, including Folders, from SharePoint List Programmatically and Efficiently

From this post http://www.praveenmodi.com/programmatically-delete-all-items-sharepoint-list/ by Praveen Modi.

///
/// Purges items and folders from a list
/// Define WSSV3 to remove list folders
///

/// The SPList you want to
/// purge items from
private static void PurgeList(SPList list)
{
Console.WriteLine("Purging list: " + list.Title);
Console.WriteLine("Base Type: " + list.BaseType.ToString());

// ===========================================================
// list.ItemCount returns a count that includes all items
// "AND" folders.
// You can't use list.Items.DeleteItemById() to remove a
// folder
// ===========================================================
System.Collections.Hashtable hItems =
new System.Collections.Hashtable(list.ItemCount);

// ===========================================================
// SPList.Items returns all list items in the entire list
// regardless of folder containment
// Note, just because list.ItemCount includes folders,
// list.Items does not.
// ===========================================================
foreach (SPListItem item in list.Items)
hItems.Add(item.ID,null);

// Remove the list items
foreach (int ID in hItems.Keys)
list.Items.DeleteItemById(ID);
// Clear the hashtable
hItems.Clear();
// ===========================================================
// SPList.Folders returns all folder items in the entire list
// regardless of parent folder containment
// ===========================================================
foreach (SPListItem item in list.Folders)
hItems.Add(item.ID,null);

// Remove the folder items
foreach (int ID in hItems.Keys)
{
list.Folders.DeleteItemById(ID);
}
}

Monday, January 3, 2011

CAML Query returns all items

I use CAML Query Builder a lot, a great tool. However, I ran into a situation that the CAML query returns all the items of a list. Thanks to Google, I found a blog entry by Steve Pietrek. His suggestions fix the problem.





Specifically, I did the following:

  1. remove the opening and closing query tag
  2. change the double quote to single quote in the query.

Wednesday, October 27, 2010

How to solve Microsoft.SharePoint.SPException: A file with the name xxx already exists. It was last modified by SHAREPOINT\system on xxx

In the workflow, if the workflow needs to update the column/field of the current workflow list item, i.e., workflowproperites.listitem, workflowproperties.listitem.update() will cause above exception. To solve this problem, the workflow needs to retrieve the listitem independently, as suggested by this blog by


My resolution is to add a simple property to my WF class. What it will do is ensure that I always load up the SPListItem every time I need it.

private SPListItem WorkflowItem
{
    get
    {
        SPDocumentLibrary library = (SPDocumentLibrary)WorkflowProperties.Web.Lists[WorkflowProperties.ListId];

        return library.GetItemById(WorkflowProperties.ItemId);
    }
}


There are many suggestions about how to fix this problem, but this one did it for me.

Friday, October 15, 2010

Start SharePoint Workflow from Web Services

Just some quick points:
  • I place the web application with the web services under the same application pool of SharePoint, also in the web services I use SPSecurity.RunWithElevatedPrivileges. Otherwise, you may run into the error message like the following: System.IO.FileNotFoundException thrown by the SPSite constructor.
  • Also I enabled web.AllowUnsafeUpdates so that to not run into security validation error.

Wednesday, October 6, 2010

Task failed because "sgen.exe" was not found: solution

When building an InfoPath solution with code behind, with web services references, you may run into above error message. The following link provides 2 solutions, but the first solution did not work for me, the second one did.

http://www.itjungles.com/dotnet/task-failed-because-sgen-exe-was-not-found-solution

Monday, August 9, 2010

What's New of SmartTools for SharePoint Time Display Bug and Fix

If you have not heard of SmartTools for SharePoint, then you need to check it out. It has several very useful SharePoint 2007 extensions to "make your life as a SharePoint user, developer or administrator a little bit easier!", to quote from the site.

However, the WhatsNew web part displays the modified date and time coloumns incorrectly, specifically, it converts the time from SharePoint to local time one time more than necessary. For example, it shows "6:56 AM" for a document last modified at "11:56 AM". The SharePoint regioinal setting is US Central Time. You can see the difference is 5 housrs, which is the difference between US Central Daylight Time and GMT.

The fix is very easy. In the source code which you can download from the site, comment line 406 and 411, and uncomment line 407 and 410. See correct code below.

                    if (modifiedDateTime.Date == DateTime.Today)
                        row["ModifiedDate"] = "Today";
                    else
                    {
                        //row["ModifiedDate"] = SPUtility.FormatDate(SPContext.Current.Web, modifiedDateTime.Date, SPDateFormat.DateOnly);
                        row["ModifiedDate"] = modifiedDateTime.Date.ToShortDateString();
                    }

                    row["ModifiedTime"] = modifiedDateTime.ToShortTimeString();
                    //row["ModifiedTime"] = SPUtility.FormatDate(SPContext.Current.Web, modifiedDateTime, SPDateFormat.TimeOnly) ;


SPUtility.FormatDate assumes the given time is UTC time and converts to local time based on regional settings (See what is good to know about SPUtility.FormatDate). When the code gets the modifiedDateTime, it is local time already. Another conversion to local time therefore is not necessary.

In SharePoint, Datetime value is stored as UTC time. When setting datetime, SharePoint converts the input to UTC and stores the UTC value; when displaying datetime, SharePoint converts the UTC time to local time.

According to this blog sharepoint web services and utc time fun and games from Andy Burns, there is some kind of problem with web services.

Friday, July 23, 2010

SPItemEventReceiver ItemAdded not firing

If you have configured ItemAdded event handler on a document library, and if you upload the same document multiple times, the first time ItemAdded event handler is fired. With the just uploaded document still in the library, subsequent uploading of the same document will not cause the ItemAdded event to fire.

I assume that SharePoint treats the subsequent uploading of the same document as an item being updated, not as being added, as in adding a new one.

Tuesday, June 8, 2010

Using SharePoint 2010 Developer Dashboard for Debugging and Performance Monitoring

Basically, we can use the following code pattern:

    using (new SPMonitoredScope("My code block (WebPart1)"))
    {
        // the code to be monitored here
    }


Please see the blog from Waldek Mastykarz for detail.

Friday, May 28, 2010

Using Session State in SharePoint 2010 - Mark Arend - Site Home - MSDN Blogs

Very good article. In summary, it explains the difference between ASP.NET Session State and State Service and how to enable ASP.NET Session State and it's implications.

If your custom SharePoint code uses ASP.NET session, please be aware of this.

Link to the article

Thursday, May 27, 2010

Date Comparison in FullTextSqlQuery

I found this forum discussion.

Basically according to Steve Curran, the date literal must be surrounded by single quotes and formatted in YYYY-MM-DD format. Note this format does not address date with time value. However, even with this format, the = comparison does not work, for example, reportDate = '2010-05-24'. The >= comparison works.

In order to make equal comparison work, I had to combine > and < together. For example:

reportDate > inputDate.AddDays(-1).ToString("yyyy-MM-dd") and reportDate < inputDate.AddDays(1).ToString("yyyy-MM-dd")

The reportDate is a Date and Time field with Date Only format.

If you know any other approaches, please let me know.

Update: Also find this blog by about datetime comparison. Must read if you do datetime comparison in custom search web part.