Wednesday, 20 November 2013

Workflow Error - Failed on Start (retrying)

If you encounter this error message "workflow error - failed on start (retrying)" in visual studio .net workflow, you can try the following solutions to fix the issue:

  • Change the Correlation Token value to be unique. The workflow and each activity should have a unique value. The workflow itself and each task you need to reference in the workflow must have a separate correlation token. Refer to this link http://msdn.microsoft.com/en-us/library/ms475438.aspx for more details. 

In the below example, I set the correlation token of the workflow in onWorkflowActivated1 to "workflowToken" and then the correlation token of the workflow task createEndorserTask to "taskToken".

correlation token

Figure 1: workflowToken


correlation token

Figure 2: taskToken



  • Check the dll in the workflow.xml (CodeBesideAssembly). It should be the same as the one in the GAC.





Tuesday, 19 November 2013

How to Save a File to SQL Database

Here are the steps on how to save a file to sql database using LINQ.


  1. Define your table. In this sample we created an Attachments table having 3 fields FileID (int), FileName (nvarchar(100)) and FileContent (varbinary(MAX)). FileContent field will contain the bytes of our file. We set it to MAX to accommodate any file size.










  1. Add your table to your repository module. In this case I used a simple LINQ to SQL just to make it simple















I created a simple repository class to expose some methods like add, save and get.

public class AttachmentRepository
{
    private DataClassesDataContext db = new DataClassesDataContext();

       public AttachmentRepository()
       {
              //
              // TODO: Add constructor logic here
              //
       }

    public void Add(Attachment at)
    {
        db.Attachments.InsertOnSubmit(at);
    }

    public void Save()
    {
        db.SubmitChanges();
    }

    public List<Attachment> GetAllAttachments()
    {
        return db.Attachments.ToList();
    }
}


  1. Layout your UI. Here we have two controls asp FileUploader and asp Button.






  1. Add a button click event on your upload button. In the code below, we only add a file to the database if there is a file uploaded using .HasFile property. Since we already have a repository using LINQ to SQL we can directly assign the Filename and FileBytes to our attachment class.

protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (FileUploadSample.HasFile)
        {
            AttachmentRepository atRepo = new AttachmentRepository();
            Attachment at = new Attachment();
            at.FileName = FileUploadSample.FileName;
            at.FileContent = FileUploadSample.FileBytes;
            atRepo.Add(at);
            atRepo.Save();
        }       
   }


  1. Verify your Database if the file was indeed saved.








Finally I added a gridview to show the uploaded data









Monday, 11 November 2013

Selecting Colors Using Microsoft FrontPage 2003

When designing a web page, sometimes you want to copy and use a specific color in an existing web site. But the problem is you don’t know what the exact color is. In this case, you can use Microsoft FrontPage 2003 to select colors by their values.

Here are the steps to follow:

1. Open the web site, picture or other file that has the color that you want to copy.

2. Open the Microsoft FrontPage and resize it to smaller window. Be sure that the FrontPage window is on the top of the page in step #1.

3. On the Formatting toolbar, click the next  to FONT COLOR   » select More Colors...
The More Colors dialog box appears.

More Colors


4. Click the Select button and then point your mouse (outside the More Colors dialog box) to the color that you want to copy or reuse. (In our example, the color of the yahoo page toolbar has been selected.)



5. Copy the hex value in the Value text box and then modify it in the format #XXXXXX.
(e.g. {F6,E8,A9} -> #F6E8A9 ). From this format, you can now use it in your web page design.




 

Thursday, 7 November 2013

Change the Redirection URL of SharePoint Buttons

When you open a site using SharePoint designer and view one of its site pages, for example EditForm.aspx, you can see the html code of the default OK and Cancel buttons in the HTML Code view. 

The html code of the buttons are:

<SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton1" Text="OK"/>

<SharePoint:GoBackButton runat="server" ControlMode="Edit" id="gobackbutton2"/>


In the above html code, you will notice that there are no available attributes / properties for the elements <SharePoint:SaveButton> and <SharePoint:GoBackButton> where you can specify or edit its redirection url. Basically, the redirection url of these buttons are being handled already by SharePoint so there is no way to make the default buttons redirect to a different url.

But there is a workaround to achieve that kind of requirement. Instead of using the default sharepoint buttons, you can use the HTML button <input type="button"> as shown below.

<input type="button" class="ms-ButtonHeightWidth" value="OK" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={}')}" />

<input type="button" class="ms-ButtonHeightWidth" value="Cancel" name="btnCancel" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={}')}" />


Here we set the class attribute equal to "ms-ButtonHeightWidth" in order to have the same look and feel as of the default SharePoint button. In the __redirect={} part of the onclick attribute value, you can put any URL you like, for example __redirect={http://www.google.com} or __redirect={/news/PressReleases/}. Please take note that there should be no quotes around the URLs passed into the __redirect directive.


Here is the full example:

<input type="button" class="ms-ButtonHeightWidth" value="OK" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={http://www.google.com}')}" />

<input type="button" class="ms-ButtonHeightWidth" value="Cancel" name="btnCancel" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={/news/PressReleases/}')}" />




   

Wednesday, 6 November 2013

Filter SharePoint List Views by Date and Time

By default if you do filtering of views by DateTime field via web, it will only filter the views by date, not including time. In order to include time, you need to modify the view using SharePoint Designer. Here are the steps on how to do it.

  1. Open the site in which the list or document library resides using Microsoft Office SharePoint Designer.
  2. Locate the list or document library and open the .aspx file associated with the view (e.g. “AllItems.aspx”)
  3. Click the Code tab and locate the CAML query associated with the filter (search on the name of your DateTime field, e.g. "StartDateTime"). 
  4. Edit the CAML query to include the IncludeTimeValue attribute (IncludeTimeValue="True"). Please note that you need to include spaces exactly as shown in the sample below: 


            &lt;Gt&gt;
             &lt;FieldRef Name=&quot;StartDateTime&quot;/&gt;
             &lt;Value Type=&quot;DateTime&quot; IncludeTimeValue="True"&gt;
              &lt;Today/&gt;
             &lt;/Value&gt;





Saturday, 2 November 2013

Filter SharePoint List Using URL Parameters

When you filter a list in SharePoint, you will notice that the parameters for filtering are appended automatically to the URL of the page that displays the list. So if you have a requirement to create a custom Search page, you can use the url parameters. For example, using SharePoint designer, you can add the list view web part on the page and then manipulate the url parameters for filtering by using javascript.

Here are the parameters that can be added in the URL to filter the SharePoint list:

  • to filter by one column

               ?FilterField1=<InternalName>&FilterValue1=<Value>

  • to filter by one column with multiple values

              ?FilterName=<InternalName>&FilterMultiValue=<value1>;<value2>
                         ** FilterMultiValue should be semicolon separated

  • to filter by two columns

              ?FilterField1=<InternalName>&FilterValue1=<Value1>&FilterField2=<InternalName>&FilterValue2=<Value2>


Note:
   <InternalName> = the internal name of the column
   <Value> = the value of the column


Examples:

1. To display SharePoint list items where Document Date = '08/16/2011'

http://www.vpc.com/sites/blog/Lists/Posts/AllPosts.aspx?FilterField1=DocumentDate&FilterValue1=08/16/2011

2. To display SharePoint list items where Category = 'Category1' and Document Date = '08/16/2011'.

http://www.vpc.com/sites/blog/Lists/Posts/AllPosts.aspx?FilterField1=PostCategory&FilterValue1=Category1&FilterField2=DocumentDate&FilterValue2=08/16/2011

3. To display SharePoint list items where Title = 'Test' OR Title = 'Sample Title'

http://www.vpc.com/sites/blog/Lists/Posts/AllPosts.aspx?FilterName=Title&FilterMultiValue=test;sample%20title

4. To display SharePoint list items where Title contains 'sample'

http://www.vpc.com/sites/blog/Lists/Posts/AllPosts.aspx?FilterName=Title&FilterMultiValue=*sample*





Internal Names of SharePoint User Profile Fields

SharePoint user profile contains information about the user such as name, title, phone number, email address, etc. It has two types, namely WSS Profile and MOSS Profile. WSS Profile can be accessed from Welcome User >> My Settings page (_layouts/userdisp.aspx?.......) while MOSS Profile can be accessed from My Site (../Person.aspx?....) and it is created when users are imported into the system from AD or LDAP.

Basically, there are two MOSS Timer jobs that control the replication of the user profiles per web application. These are Profile Synchronization and Quick Profile Synchronization. The difference between the two is Profile Synchronization updates the WSS profile whereas Quick Profile Synchronization updates the MOSS profiles. Both of these jobs can be found in Central Administration -> Operations -> Timer Job definitions. 

If you want to access the user profile columns / fields in code, you need to know its equivalent internal names. Actually, the internal names of the columns are different depending on the types of user profile.

So for your reference, I have listed below the user profile fields and its corresponding internal names.


WSS Profile (User Information List) MOSS Profile (SSP User Profile)
Display Name Internal Name Display Name Internal Name
Account Name Account name AccountName
First name FirstName First name FirstName
Last name LastName Last name LastName
Name Title Name PreferredName
Work phone WorkPhone Work phone WorkPhone
Office Office Office Office
Department Department Department Department
Title JobTitle Title Title
Work e-mail EMail Work e-mail WorkEmail
User name UserName