private File GetFile(object id) { var file = clientContext.Web.GetFileByServerRelativeUrl((string)id); clientContext.Load(file); clientContext.Load(file.ListItemAllFields); try { clientContext.ExecuteQuery(); } catch (Exception ex) { SharePointProviderInfoHelper.PublishFolder(MakeId(GetParentFolderId(id))); var serverException = (ServerException)ex; if (serverException.ServerErrorTypeName == (typeof(FileNotFoundException)).ToString()) { return(null); } return(new SharePointFileErrorEntry(file.Context, file.Path) { Error = ex.Message, ID = id }); } return(file); }
private Folder GetFolder(object id) { if ((string)id == "") { id = SpRootFolderId; } var folder = clientContext.Web.GetFolderByServerRelativeUrl((string)id); clientContext.Load(folder); clientContext.Load(folder.Files, collection => collection.IncludeWithDefaultProperties(r => r.ListItemAllFields)); clientContext.Load(folder.Folders); try { clientContext.ExecuteQuery(); } catch (Exception ex) { SharePointProviderInfoHelper.PublishFolder(MakeId(GetParentFolderId(id))); var serverException = (ServerException)ex; if (serverException.ServerErrorTypeName == (typeof(FileNotFoundException)).ToString()) { return(null); } return(new SharePointFolderErrorEntry(folder.Context, folder.Path) { Error = ex.Message, ID = id }); } return(folder); }
public Folder CopyFolder(object id, object toFolderId) { SharePointProviderInfoHelper.PublishFolder(MakeId(toFolderId)); var folder = GetFolderById(id); if (folder is SharePointFolderErrorEntry) { return(folder); } return(MoveFld(folder, toFolderId + "/" + GetFolderById(id).Name, false)); }
public string MoveFolder(string id, string toFolderId) { SharePointProviderInfoHelper.PublishFolder(MakeId(id), MakeId(GetParentFolderId(id)), MakeId(toFolderId)); var folder = GetFolderById(id); if (folder is SharePointFolderErrorEntry) { return(MakeId(id)); } return(MakeId(MoveFld(folder, toFolderId + "/" + GetFolderById(id).Name).ServerRelativeUrl)); }
public object RenameFolder(object id, string newTitle) { SharePointProviderInfoHelper.PublishFolder(MakeId(id), MakeId(GetParentFolderId(id))); var folder = GetFolderById(id); if (folder is SharePointFolderErrorEntry) { return(MakeId(id)); } return(MakeId(MoveFld(folder, GetParentFolderId(id) + "/" + newTitle).ServerRelativeUrl)); }
public void DeleteFolder(string id) { SharePointProviderInfoHelper.PublishFolder(MakeId(id), MakeId(GetParentFolderId(id))); var folder = GetFolderById(id); if (folder is SharePointFolderErrorEntry) { return; } folder.DeleteObject(); clientContext.ExecuteQuery(); }
public File CopyFile(string id, string toFolderId) { SharePointProviderInfoHelper.PublishFolder(MakeId(toFolderId), MakeId(GetParentFolderId(id))); var file = GetFileById(id); if (file is SharePointFileErrorEntry) { return(file); } var newUrl = toFolderId + "/" + file.Name; file.CopyTo(newUrl, false); clientContext.ExecuteQuery(); return(file); }
public string MoveFile(string id, string toFolderId) { SharePointProviderInfoHelper.PublishFile(MakeId(id), MakeId(GetParentFolderId(id))); SharePointProviderInfoHelper.PublishFolder(MakeId(toFolderId)); var file = GetFileById(id); if (file is SharePointFileErrorEntry) { return(MakeId()); } var newUrl = toFolderId + "/" + file.Name; file.MoveTo(newUrl, MoveOperations.Overwrite); clientContext.ExecuteQuery(); return(MakeId(newUrl)); }
public File CreateFile(string id, Stream stream) { byte[] b; using (var br = new BinaryReader(stream)) { b = br.ReadBytes((int)stream.Length); } var file = clientContext.Web.RootFolder.Files.Add(new FileCreationInformation { Content = b, Url = id, Overwrite = true }); clientContext.Load(file); clientContext.Load(file.ListItemAllFields); clientContext.ExecuteQuery(); SharePointProviderInfoHelper.AddFile("spointf-" + MakeId(id), file); SharePointProviderInfoHelper.PublishFolder(MakeId(GetParentFolderId(id))); return(file); }