20 May 2007

Integrate CRM with WSS 3.0 Picture Library

I worked for a project which needs integrate CRM with WSS 3.0 picture library.
The requirement was: Each account has it's own picture library in WSS, so the pictures could be use in CRM report etc.
Here's the code:


public partial class _Default : System.Web.UI.Page
{
string accountGUID = "";
protected void Page_Load(object sender, EventArgs e)
{
string entityId = Request.QueryString["oId"];
Guid accountId = (entityId == null) ? (new Guid("00000000-0000-0000-0000-000000000000")) : new Guid(entityId);
accountGUID = accountId.ToString();
string url = "http://WSS:6666/PL/" + accountGUID; // PL is a picture library in WSS 3.0

if (CheckUrl(url))
{
Response.Redirect(url);
}
else
{
Label1.Text = "This account doesn't has a Pictures Library, please create a one for it.";
}
}

public static bool CheckUrl(string url)
{
//check if the url(pictures library) is existing
HttpWebResponse httpResponse = null;

try
{
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
return (httpResponse.StatusCode == System.Net.HttpStatusCode.OK);
}
catch (Exception ex)
{
return false;
}
}

protected void Button1_Click(object sender, EventArgs e)
{
//Response.Redirect("http://WSS:6666/PL/Forms/Upload.aspx?Type=1");
SPSite Site = new SPSite("http://WSS:6666"); //site url
SPWeb Web = Site.OpenWeb();
Site.AllowUnsafeUpdates = true;
Web.AllowUnsafeUpdates = true;
SPFolder rootFolder = Web.GetFolder("PL"); // PL is a picture library in WSS 3.0
rootFolder.SubFolders.Add(accountGUID);
Page_Load(null, null);
}
}

1 comment:

Unknown said...

Keep up the fantastic piece of work, I read few blog posts on this web site and I believe that your site is real interesting and has lots of great information. ERP Software in Mumbai || System Software || CRM Software in Mumbai || MLM Software