How to Copy Files from a Server Share to a SharePoint 2010 Library – ASP.Net C# and Command Line

SharePoint Libraries you can “Open with Windows Explorer” I spent some time trying to figure out how to automate file management that I could do using drag and drop. Trouble was, to use the SharePoint libraries you have to develop and run your application on a SharePoint server, which I didn’t want to do. After dorking around on the command line I found that you could assign a drive letter to the SharePoint library via “net use”.

Command Line:

net use r: /delete
net use s: /delete
net use r: \\Server\Share
net use s: https://SharePointServer/Library
del s:. /F/Q
copy r:. s:
net use s: /delete
net use r: /delete

That share shows up in Windows Explorer as a drive mapping that looks like this:

MyLibrary (\\SharePointServer@SSL\DavWWWRoot\)

Well, heck! If that’s the case then the following aught to work – and does!

ASP.Net C#:

string mysharepointlibrary = @"\\SharePointServer@SSL\DavWWWRoot\MyLibrary\";
Array.ForEach(Directory.GetFiles(mysharepointlibrary), File.Delete);
DirectoryInfo dir = new DirectoryInfo(MapPath("~/uploadfolder"));
files = dir.GetFiles();
foreach (FileInfo file in files)
{
  File.Copy(file.FullName, Path.Combine(mysharepointlibrary , file.Name), true);
}

More information:

http://www.iis.net/learn/publish/using-webdav/using-the-webdav-redirector

WebClient Service uses the Local Service account by default.

Advertisements

One thought on “How to Copy Files from a Server Share to a SharePoint 2010 Library – ASP.Net C# and Command Line

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s