Skip to content

Instantly share code, notes, and snippets.

@Krizzzn
Last active December 25, 2015 04:39
Show Gist options
  • Save Krizzzn/6919211 to your computer and use it in GitHub Desktop.
Save Krizzzn/6919211 to your computer and use it in GitHub Desktop.
Upload one or many files to Sharepoint
using System.Net;
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential("*******", "********");
Action<string> act = (imageName) => {
Console.Write("uploading " + imageName + " ");
webClient.Headers.Add("Overwrite", "T");
webClient.UploadFile("http://*************/User%20Photos/Profile%20Pictures/" + imageName, "PUT", imageName);
Console.WriteLine("Done");
};
var currentDirectory = System.IO.Directory.GetCurrentDirectory();
var files = System.IO.Directory.EnumerateFiles(currentDirectory, "*.jpg")
.Select(System.IO.Path.GetFileName)
.ToList();
Console.WriteLine("uploading {0} files.", files.Count());
files.ForEach(act);
using System.Net;
public static void UploadImage(string imageName){
WebClient webClient = new WebClient();
webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
webClient.Headers.Add("Overwrite", "T");
webClient.UploadFile("http://{fucking_awesome_url}/PublishingImages/" + imageName, "PUT", "images\\" + imageName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment