How to programatically upload file on sharepoint site?

  • Thread starter Thread starter Elezard
  • Start date Start date
E

Elezard

Guest
Hi,

I'm trying to upload the file on sharepoint classic site. However, I am encountering permission issue but I"m already admin in the site. Btw, I can upload the file manually. Pls help me.

using (FileStream fs = new FileStream(file, FileMode.Open))
{
FileCreationInformation flciNewFile = new FileCreationInformation
{
ContentStream = fs,
Url = "/" + getFileName[6],
Overwrite = true
};

SPFile spFile = styleLibrary.RootFolder.Files.Add(flciNewFile);

context.Load(spFile);
context.ExecuteQuery();

var ifExists = spFile.ServerRelativeUrl;

try
{

spFile.CheckIn("Checked in by System", CheckinType.MajorCheckIn);
context.Load(spFile);
context.ExecuteQuery();

Console.WriteLine("{0} file uploaded.", getFileName[6]);

}
catch (Exception e)
{
Console.WriteLine("An error occurred while checking in {0}. Error: {1}", getFileName[6], e);
}

Continue reading...
 
Back
Top