Sunday, February 1, 2009

Upload a document in DOCUMENT LIBRARY in WSS 3.0 programatically.

As I mentioned there are two ways to interact with WSS 3.0
1)WebService Approach
2)Object model approach.

So below is the code you have to do while following the service approach to upload a document programatically.


[WebMethod]
public bool UploadTemplate(Byte[] fileInBytes, string FileName, string MetaInformation)
{
try
{
NetworkCredential objCredential = new NetworkCredential();
objCredential.Domain = ConfigurationSettings.AppSettings["NetworkDomain"];
objCredential.UserName = ConfigurationSettings.AppSettings["NetworkUserName"];
objCredential.Password = ConfigurationSettings.AppSettings["NetworkPassword"];

string[] destURI = { ConfigWrapper.WebSiteUrl + ConfigWrapper.DoucmentDirectory + "/" + FileName };

Copy webCopyObj = new Copy();
webCopyObj.Credentials = objCredential;
webCopyObj.Url = ConfigWrapper.CopyServiceUrl;

FieldInformation myFieldInfo = new FieldInformation();
myFieldInfo.DisplayName = "MetaInformation";
myFieldInfo.Value = MetaInformation;
myFieldInfo.InternalName = "MetaInformation";
myFieldInfo.Type = FieldType.Text;
FieldInformation[] myFieldInfoArray = { myFieldInfo };

CopyResult myCopyResult2 = new CopyResult();
CopyResult[] myCopyResultArray = { myCopyResult2 };

CopyResult[] result;

uint documentId = webCopyObj.CopyIntoItems("http://null", destURI, myFieldInfoArray.ToArray(), fileInBytes, out result);
byte[] temp;
uint tempId = webCopyObj.GetItem(destURI[0], out myFieldInfoArray, out temp);
Guid myItemGUID = myFieldInfoArray[0].Id;
return true;
}
catch
{
return false;
}
}



webCopyObj will be the object of the copy web service taken from the site.So for example you have to include the web reference from http://localhost:15182/_vti_bin/Copy.asmx.which referes to /_vti_bin/Copy.asmx.


Will write about the second approach (Object model approach) later.


ConfigWrapper is the object of the class written for fetcing the information from appSetting section from web.config

Monday, January 5, 2009

Sharepoint Starting.

Hi,

I am new to sharepoint these days and I have seen some pepole who have heard about this sharpoint but never used its feature.

So, I decieded to share my knowledge upon share point with the Guys who are just starting this technology.

I came to know that we can access sharepoint programatically also.The good thing about sharepoint is it exposes 2 ways to interact with sharepoint site.

1. Sharepoint as a object model.
2. As Web Service Interaction.

Well hope you have heard of WSS 3.0. The full form of WSS is Windows Sharepoint Server. It exposes some web service for the developers who want to handle the site programatically and when you install sharepoint 2007 it also give some some more web services which a developer and use to manage the web site.

The second approach is the object model approach. In this approach developer has to include the dll and play with the web site as a object model (like namespaces, classes and Object etc.)

Hope this helps for the beginners.I will keep updating you about the sharepoint or WSS R&D, I will do.

Thanks