Hi, We are trying to add code to create folder in sharepoint site. we have come up with a method which works perfectly fine in VS 2017. But when we add it to a code stage we are getting the below errors. Framework : 4.0 & Any CPU
1) Compile error at line 0: } expected.
2) Compiler error at top section line 102: type or name space definition or end of file expected.
Please find below the code which is in code stage
public string checkAndCreateFolder(string TargetPath,string FolderName, string UserName, string Password)
{
try
{
string returnstring="";
Uri targetUri = new Uri(TargetPath);
var sitePath = string.Format("{0}{1}{2}/{3}{4}", targetUri.Scheme, Uri.SchemeDelimiter, targetUri.Host, targetUri.Segments[1], targetUri.Segments[2]);
var context = new ClientContext(targetUri);
context.ExecutingWebRequest += ctx_ExecutingWebRequest;
context.RequestTimeout = 3600000;
// If the settings specify an user and password for the SP connection use them.
if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
{
context.Credentials = new NetworkCredential(UserName, Password);
}
else
{
context.Credentials = CredentialCache.DefaultCredentials;
}
context.ExecuteQuery();
Folder test = context.Web.GetFolderByServerRelativeUrl("EngagementDocumentLibrary/"+FolderName);
context.Load(test);
try
{
context.ExecuteQuery();
if (test.Name != null)
{
returnstring = "folder already exists";
}
}
catch (Exception ex)
{
context.Web.Folders.Add("EngagementDocumentLibrary/" + FolderName);
context.ExecuteQuery();
returnstring = "folder created Succesfully";
}
return returnstring;
}
catch (Exception ex)
{
throw ex;
}
}
private void ctx_ExecutingWebRequest(object sender, WebRequestEventArgs e)
{
if (e != null)
{
e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
}
}