Click here to Skip to main content
16,011,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have windows application. i want to upload the files from local machine to sharepoint document library with metadata. here the metadata value should be entered into textbox. I have used the following coding but i got error "The remote server returned an error: (400) Bad Request." in context.ExecuteQuery(); this line.

private void btn_Upload_Click_1(object sender, EventArgs e)
{
public string Photos = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Photo");
string pathInf = Path.Combine(Photos,"Image.png");
ClientContext context = new ClientContext("http://Sharepointsite");
Web web = context.Web;
List list = web.Lists.GetByTitle("Shared Documents");
Microsoft.SharePoint.Client.FileCreationInformation fp1 = new FileCreationInformation();
fp1.Content = System.IO.File.ReadAllBytes(pathInf);
fp1.Url = "/Shared Documents/Scanning/" + "Image.png";
Microsoft.SharePoint.Client.File uploadFiles = list.RootFolder.Files.Add(fp1);
context.Load(uploadFiles);
context.ExecuteQuery();
ListItem items = uploadFiles.ListItemAllFields;
items["Custom1"] = textMetadata.Text;
items.Update();
context.ExecuteQuery();
}
Posted
Updated 28-Jul-13 19:47pm
v3

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