Wednesday, November 04, 2009

Programatically checking if the file exists in the specified location in Sharepoint

SPSite Site = new SPSite(SITE_URL);
SPWeb Web = Site.OpenWeb();
Bool isFileExists;
if(Web.GetFile(FilePath).Exists)
isFileExists = true;
else
isFileExists = false;

Method for converting a number to base in C#.net

public static string ConvertToBase(int num, int nbase)
{
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

// check if we can convert to another base
if (nbase <> chars.Length)
return "";

int r;
String newNumber = "";

// in r we have the offset of the char that was converted to the new base
while (num >= nbase)
{
r = num % nbase;
newNumber = chars[r] + newNumber;
num = num / nbase;
}
// the last number to convert
newNumber = chars[num] + newNumber;

return newNumber;
}

Regular Expression for Validating Email

^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$

How to Clone List in C#.net

To Copy List1 to List 2;

List List1;
//Create an array of strings
string[] arrStrList=new string[List1.Count];
//Copy the List to array of strings
List1.CopyTo(arrStrList);
//Define a new list
List List2= new List(List1.Count);
//Add array of strings to new list
List2.AddRange(arrStrList);

How to read and update LookUp Field in Sharepoint

//To Read LookUp Field
public static string ReadLookupValue(SPListItem item, string columnName)
{
SPFieldLookupValue lookupField = new SPFieldLookupValue(item[columnName].ToString());
return lookupField.LookupValue;
}

//To Update LookUp Field

int ListItemID = GetListItemID("ListWithLookUpColumn","ValueToBeUpdate");
ListItem[LookUpFieldColumnName] = ListItemID;
ListItem.Update();

/////

public static int GetListItemID(string ListName, string ListColumnValue)
{
int ListItemID=0;
try
{
SPSite Site = new SPSite(SITE_URL);
SPWeb Web = Site.OpenWeb();
SPList List = Web.Lists[ListName];
SPListItemCollection ListItems = List.Items;

int ListItemCount = ListItems.Count;
for (int i = 0; i < ListItemCount; i++)
{
SPListItem ListItem = ListItems[i];
if (ListItem["Title"].ToString() == ListColumnValue)
{
ListItemID =Convert.ToInt32(ListItem["ID"].ToString());
break;
}

}
return ListItemID;
}
catch (Exception ex)
{
return 0;
}
}

Programatically Sending Mails only to Outlook users and not sending to out side emails like Gmail,Yahoo etc.

I faced a problem in sending mails to outside of our domain.
I figured it out that i missed to add the following line of code before sending mail.

SmtpMail.SmtpServer = "EmailServername".

How to dislay Hand Icon for Buttons on mouse over in Infopath Forms

To display the Hand icon instead of pointer on mouse over of Button in Infopath Form, follow the steps below:

1) Open the Infopath form(InfopathForm.xsn) in design mode.

2) Save the form as Source Files ( Go to File menu, click on "Save As Source Files...)

3) Go to the saved Source Files location and open the xsl file(notice that it will create an xsl file for each view in the Infopath form) in an editor.

4) Search for "type="button"" and for that button style add "cursor:pointer". Save the file

5) Open "manifest.xsf" file in design mode from the same location.

6) Publish the manifest.xsf file.

7) Upload the file to Sharepoint Site.

8) Open the form in Sharepoint site and check if the buhand icon is displayed on button mouse over.

Wednesday, June 10, 2009

Error in accessing Web Service in VSTA code of Infopath Form

When I am trying to access the web serice method in the VSTA code of Infopath form, I was getting the following error message:

The error message is “There is an error in XML document (1, 302)."

The stack trace is “ at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

at EmpSepChkLst.AD_SEARCH.NDAWebService.SerachUserInDomain(String UserName)

at EmpSepChkLst.CommonFunctions.GetUserInfo(String CurrentUserId)”.


The solution for this is:

You need to publish the infopath form with full permission( Tools -> Form Options -> Security and Trust -> Select Full trust). I was publishing with "Domain" permissions and it was throwing the error while opening the infopath form from Sharepoint Document Library.

Error while submitting Infopath form to a SharePoint Document Library

I was getting the following error when submitting the Info path Form to a SharePoint Document library:
"An exception of type 'System.Net.WebException' occurred in Microsoft.Office.InfoPath.Server.dll but was not handled in user code

Additional information: A value in the form may be used to specify the file name. If you know the value in the form that specifies the file name, revise it and try again. Otherwise, contact the author of the form template."


You need to make the changes in the share point submit data connection. The following steps will walk you through

1. Open form in Design Form
2. Go to Tools in menu bar
3. Select data connection
4. Select the Dta connection name that you had used to submit the form to Share Point
5. Click on 'Modify' button
6. Check 'Allow overwrites if file exists' check box
7. click on 'Next' button
8. Click on 'Finish' button
9. Click on 'Close' button
10. Save the form and republish the form to Your form Library

Monday, June 08, 2009

Useful SharePoint Links

Packaging and Deploying Features in SharePoint
http://msdn.microsoft.com/en-us/magazine/cc163428.aspx

WSPBuilder
http://wspbuilder.codeplex.com/

Developer Getting Started Guide
Introduction to SharePoint Products and Technologies for the Professional .NET Developer
http://msdn.microsoft.com/en-us/library/cc537498.aspx#MOSSIntroToNet_BuildingSharePointSolutionsUsingVisualStudio2008


Windows SharePoint Services (WSS) Developer Center
http://msdn.microsoft.com/en-us/sharepoint/default.aspx

Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 1 of 2)
http://msdn.microsoft.com/en-us/library/bb530302.aspx

Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 2 of 2)
http://msdn.microsoft.com/en-us/library/bb530301.aspx

SharePoint Products and Technologies Customization Best Practices
http://msdn.microsoft.com/en-us/library/bb861954.aspx

Windows SharePoint Services 3.0 SDK
http://msdn.microsoft.com/en-us/library/ms441339.aspx


Microsoft Office SharePoint Server 2007 SDK
http://msdn.microsoft.com/en-us/library/ms550992.aspx

Team-Based Development in Microsoft Office SharePoint Server 2007
http://msdn.microsoft.com/en-us/library/bb428899.aspx

Permissions for Running Customer Applications Against SharePoint
1. Grant rights to Remote Desktop onto Central Admin server
2. Add to Farm Admin group
3. Add to Site Collection Admin on Desired Site
4. Ensure DBO Access on Content DB of Desired Site
5. Add to Site Collection Admin on Central Admin
6. Ensure DBO Access on Central Admin Content DB
7. Add to Site Collection Admin on SSP
8. Ensure DBO Access on SSP Content DB
Using Server Side Data Connections in Forms
http://office.microsoft.com/en-us/infopath/HA100929071033.aspx?pid=CH100598301033

http://blogs.msdn.com/infopath/archive/2007/03/21/infopath-data-connections-part-1.aspx

Using CAML and Data Fields References
http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-

http://weblogs.asp.net/gunnarpeipman/archive/2008/10/29/sharepoint-for-developers-3-3-hands-on-querying-lists.aspx

Using Profile Data Through a MOSS Web Service
http://blogs.msdn.com/infopath/archive/2007/03/07/get-the-user-profile-through-moss-web-services.aspx

SharePoint Explorer & SWAT Links
http://blog.mondosoft.com/ontolica/archive/2007/02/15/SharePoint-Explorer-for-WSS3.aspx

http://www.idevfactory.com/products/swat/

Running with Elevated Privileges

http://msdn.microsoft.com/en-us/library/aa543467.aspx

http://geekswithblogs.net/DanielC/archive/2008/01/28/sharepoint-security-runwithelevatedprivileges.aspx

Workflows with Windows Workflow Foundation and InfoPath

http://weblog.vb-tech.com/nick/archive/2007/02/25/2207.aspx

Worflow HowTwo’s from the SDK
http://msdn.microsoft.com/en-us/library/ms497003.aspx