Below is my method which is meant to copy a file from a folder on my desktop to the sharepoint document library shared documents.
Its giving me error on SaveChanges method call, error shows me this
"There is no file with URL 'http://---------/division1/shared documents/strikers_logo.jpg' in this Web " "An error occurred while processing this request."
public void copytosharepoint()
{
try
{
ChsmainDataContext sharePoint = new ChsmainDataContext(new Uri("http://rajum-pc:40613/_vti_bin/listdata.svc"));
sharePoint.Credentials = System.Net.CredentialCache.DefaultCredentials;
using (FileStream file = File.Open(@"C:\Users\rmirani\Downloads" + workflowProperties.Item.File.Name, FileMode.Open))
{
string path = "/division1/shared documents/"+workflowProperties.Item.File.Name;
string contentType = workflowProperties.Item.ContentType.Name;
SharedDocumentsItem documentItem = new SharedDocumentsItem()
{
ContentType = contentType,
Name = workflowProperties.Item.File.Name,
Path = path,
Title = workflowProperties.Item.File.Title
};
sharePoint.AddToSharedDocuments(documentItem);
sharePoint.SetSaveStream(documentItem, file, false, contentType, path);
sharePoint.SaveChanges();
}
// stream.Flush();
}
catch (Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("RHM Test Logs", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, null);
}
}