I need to upload files from my PC to a remote sharepoint server, I have an application with the following code :
using (SPSite oSite = new SPSite(_serverPath))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
if (!System.IO.File.Exists(txtFileUpload.Text))
throw new FileNotFoundException("File not found.", txtFileUpload.Text);
SPFolder myLibrary = oWeb.Folders[documentLibraryName];
//Prepare to upload ::
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName(txtFileUpload.Text);
FileStream fileStream = File.OpenRead(txtFileUpload.Text);
//Upload document ::
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
//Commit ::
myLibrary.Update();
}
}
Now I have referenced the dll file "Microsoft.SharePoint" by copy the file from the server where sharepoint is installed (as my PC that running the uploading application is not installing sharepoint) when i try to run the application i got the following error :
"Could not load file or assembly 'Microsoft.SharePoint.Library, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified."
So how can i solve this problem although i don't have sharepoint installed at my PC and i can't install it?
Thanks in advance, Hope my question is to be clear!.
You cannot use visual studio to develop Sharepoint Solutions on client machine with Server Object Model. Please check - http://msdn.microsoft.com/en-us/library/ee554869.aspx and http://msdn.microsoft.com/en-us/library/ee231582.aspx.
However you can develop using Client Object model on the client machine by referencing Microsoft.Sharepoint.Client
and Microsoft.Sharepoint.Client.Runtime
from sharepoint server.
You can check this article to see how you can do the same using Client object model - http://www.codeproject.com/Articles/103503/How-to-upload-download-a-document-in-SharePoint-20
Hope this helps.