Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

How to upload a document in SharePoint site using wss3.0 programming ?

  Asked By: Damaris    Date: Nov 22    Category: Sharepoint    Views: 1285

You can find the object model in WSS V3.0 SDK very clearly and also find the below code
string strSrcURL=fleUpload.Value;
string strDestURL=txtSiteURL.Text;
string strPath = strSrcURL;
string strDestination = "testLib";
FileStream fStream = new FileStream(strPath, System.IO.FileMode.Open);
byte[] binFile = new byte[(int)fStream.Length];
fStream.Read(binFile, 0, (int)fStream.Length);
fStream.Close();
string str = UploadDocument(strFile, binFile, strDestination);

public string UploadDocument(string fileName, byte[] fileContents, string pathFolder)
{
if ( fileContents == null)
{
return "Null Attachment";
}
try
{

SPWeb site = SPControl.GetContextWeb(Context);
site.AllowUnsafeUpdates=true;
SPFolder folder = site.GetFolder(pathFolder);
string fileUrl = fileName;
SPFile file = folder.Files.Add(fileUrl, fileContents);
return file.TimeCreated.ToLongDateString()+ "::" + file.Title;
}
catch (System.Exception ee)
{
return ee.Message + "::" + ee.Source;
}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: