Wednesday, December 10, 2008

Get SitID/WebID using sharepoint webservice

public Guid GetSiteID(string UserName, string Password, string Domain, string SiteURL)
{

Guid SiteGuid = Guid.Empty;

try

{

SiteData.SiteData site = new TP.WebService.SiteData.SiteData();

site.Url = SiteURL + "/_vti_bin/sitedata.asmx";

site.Credentials = new System.Net.NetworkCredential(UserName, Password, Domain);

site.PreAuthenticate = true;

SiteData._sWebMetadata webMetaData;

SiteData._sWebWithTime[] arrWebWithTime;

SiteData._sListWithTime[] arrListWithTime;

SiteData._sFPUrl[] arrUrls;

string roles; string[] roleUsers; string[] roleGroups;

uint i = site.GetWeb(out webMetaData, out arrWebWithTime, out arrListWithTime, out arrUrls, out roles, out roleUsers, out roleGroups);

SiteGuid = new Guid(webMetaData.WebID);

}

catch (Exception)

{

}

return SiteGuid;

}