Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i wan to upload the document on sharepoint 2010 site using c#.net i use below code but i not understand the parameter byte[] documentStream.


-so which value pass in parameter byte[] documentStream any idea about this help me.

public void UploadDocument(string siteURL, string documentListName, string documentListURL, string documentName, byte[] documentStream)
{
try
{
using (ClientContext clientContext = new ClientContext(siteURL))
{

//Get Document List
Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);

var fileCreationInformation = new FileCreationInformation();
//Assign to content byte[] i.e. documentStream

fileCreationInformation.Content = documentStream;
//Allow owerwrite of document

fileCreationInformation.Overwrite = true;
//Upload URL

fileCreationInformation.Url = siteURL + "/" + documentListURL + "/" + documentName;

Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
fileCreationInformation);

//Update the metadata for a field having name "DocType"
uploadFile.ListItemAllFields["DocType"] = "Favourites";

uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();

}
}
catch (Exception ex)
{
}
finally
{
}

}


- i use this code but it's give error parameter content not null.
- i try googling but i not get exactly meaning of last parameter.

-so any idea about which parameter pass in method please help me.

Thank you.
Posted
Updated 5-Jun-13 3:04am
v2

1 solution

try this:
try
            {
                string[] domainUserName = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[Constants.KeyDomainUserName]).Split('\\');
                string password = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[Constants.KeyPassword]);
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(domainUserName[1], password, domainUserName[0]);
                using (ClientContext clientContext = new ClientContext(spSiteUrl))
                {
                    clientContext.Credentials = credentials;
                    Web oWeb = clientContext.Web;
                    clientContext.Load(
                        oWeb,
                        website => website.Title);
                    clientContext.ExecuteQuery();

                    Microsoft.SharePoint.Client.File uploadFile = UploadFileToLibrary(file, fileName, ref fileRelativeUrl, overwriteFlag, clientContext);
                    ListItem item = uploadFile.ListItemAllFields;
                    item["Title"] = title;  //Set the metadata
                    item.Update();
                    clientContext.ExecuteQuery();
                }
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900