I would like to help me with this task if it is possible. I would like to be able to upload files to folders on Sharepoint Online. At the moment, I can only upload to libraries. Below is the code that I am currently using.
private void BtnUpload_Click(object sender, EventArgs e)
{
siteURL += "/" + tbDept.Text;
try
{
using (ClientContext ctx = new ClientContext(siteURL))
{
SecureString passWord = new SecureString();
foreach (var c in logUser.getPassword())
{
passWord.AppendChar(c);
}
ctx.Credentials = new SharePointOnlineCredentials(logUser.getUsername(), passWord);
Web web = ctx.Web;
foreach (string fname in arrAllFiles) //arrAllFiles --> contains multiple files to be uploaded
{
FileCreationInformation newFile = new FileCreationInformation();
newFile.Overwrite = true;
newFile.Content = System.IO.File.ReadAllBytes(fname);
newFile.Url = System.IO.Path.GetFileName(fname);
List docs = web.Lists.GetByTitle(tbLibrary.Text); //tbLibrary --> Library's Name
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
ctx.ExecuteQuery();
}
MessageBox.Show("Upload Complete!");
siteURL = "https://mycompany.sharepoint.com";
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
siteURL = "https://mycompany.sharepoint.com";
}
}
The code is working fine. I just need to add functionality in order to upload files to a specific folder in a library.
Thank you in advance.