C# Class Microsoft.SharePoint.Client.FileFolderExtensions

Mostrar archivo Open project: OfficeDev/PnP-Sites-Core

Public Methods

Method Description
ApproveFile ( this web, string serverRelativeUrl, string comment ) : void

Approves a file

CheckInFile ( this web, string serverRelativeUrl, CheckinType checkinType, string comment ) : void

Checks in a file

CheckOutFile ( this web, string serverRelativeUrl ) : void

Checks out a file

ConvertFolderToDocumentSet ( this list, Folder folder ) : Folder

Converts a folder with the given name as a child of the List RootFolder.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

ConvertFolderToDocumentSet ( this list, string folderName ) : Folder

Converts a folder with the given name as a child of the List RootFolder.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

CreateDocumentSet ( this folder, string documentSetName, ContentTypeId contentTypeId ) : Folder

Creates a new document set as a child of an existing folder, with the specified content type ID.

var setContentType = list.BestMatchContentTypeId(BuiltInContentTypeId.DocumentSet); var set1 = list.RootFolder.CreateDocumentSet("Set 1", setContentType);

CreateFolder ( this web, string folderName ) : Folder

Creates a folder with the given name as a child of the Web. Note it is more common to create folders within an existing Folder, such as the RootFolder of a List.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

DoesFolderExists ( this web, string serverRelativeFolderUrl ) : bool

Checks if a specific folder exists

EnsureFolder ( this web, Folder parentFolder, string folderPath ) : Folder

Ensure that the folder structure is created. This also ensures hierarchy of folders.

EnsureFolder ( this web, string folderName ) : Folder

Checks if the folder exists at the top level of the web site, and if it does not exist creates it. Note it is more common to create folders within an existing Folder, such as the RootFolder of a List.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

EnsureFolderPath ( this web, string webRelativeUrl ) : Folder

Check if a folder exists with the specified path (relative to the web), and if not creates it (inside a list if necessary)

If the specified path is inside an existing list, then the folder is created inside that list.

Any existing folders are traversed, and then any remaining parts of the path are created as new folders.

FindFiles ( this web, string match ) : List

Finds files in the web. Can be slow.

FolderExists ( this web, string folderName ) : bool

Checks if the folder exists at the top level of the web site.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

GetFile ( this folder, string fileName ) : File

Gets a file in a document library.

GetFileAsString ( this web, string serverRelativeUrl ) : string

Returns a file as string

PublishFile ( this web, string serverRelativeUrl, string comment ) : void

Publishes a file existing on a server url

ResolveSubFolder ( this folder, string folderName ) : Folder

Gets a folder with a given name in a given Microsoft.SharePoint.Client.Folder

SaveFileToLocal ( this web, string serverRelativeUrl, string localPath, string localFileName = null, bool>.Func fileExistsCallBack = null ) : void

Saves a remote file to a local folder

UploadFile ( this folder, string fileName, string localFilePath, bool overwriteIfExists ) : File

Uploads a file to the specified folder.

UploadFileWebDav ( this folder, string fileName, string localFilePath, bool overwriteIfExists ) : File

Uploads a file to the specified folder by saving the binary directly (via webdav).

VerifyIfUploadRequired ( this serverFile, Stream localStream ) : bool

Used to compare the server file to the local file. This enables users with faster download speeds but slow upload speeds to evaluate if the server file should be overwritten.

VerifyIfUploadRequired ( this serverFile, string localFile ) : bool

Used to compare the server file to the local file. This enables users with faster download speeds but slow upload speeds to evaluate if the server file should be overwritten.

Private Methods

Method Description
ConvertFolderToDocumentSetImplementation ( this list, Folder folder ) : Folder

Internal implementation of the Folder conversion to Document set

CopyStream ( Stream source, Stream destination ) : void
CreateFolderImplementation ( FolderCollection folderCollection, string folderName, Folder parentFolder = null ) : Folder
EnsureFolderImplementation ( FolderCollection folderCollection, string folderName, Folder parentFolder = null ) : Folder
FolderExistsImplementation ( FolderCollection folderCollection, string folderName ) : bool
ParseFiles ( Folder folder, string match, ClientContext context, List &foundFiles ) : void
PublishFileToLevel ( this file, FileLevel level ) : void
SetFileProperties ( this file, string>.IDictionary properties, bool checkoutIfRequired = true ) : void
UploadFile ( this folder, string fileName, Stream stream, bool overwriteIfExists ) : File
UploadFileWebDav ( this folder, string fileName, Stream stream, bool overwriteIfExists ) : File
WildcardToRegex ( string pattern ) : string

Method Details

ApproveFile() public static method

Approves a file
public static ApproveFile ( this web, string serverRelativeUrl, string comment ) : void
web this The web to process
serverRelativeUrl string The server relative url of the file to approve
comment string Message to be recorded with the approval
return void

CheckInFile() public static method

Checks in a file
public static CheckInFile ( this web, string serverRelativeUrl, CheckinType checkinType, string comment ) : void
web this The web to process
serverRelativeUrl string The server relative url of the file to checkin
checkinType CheckinType The type of the checkin
comment string Message to be recorded with the approval
return void

CheckOutFile() public static method

Checks out a file
public static CheckOutFile ( this web, string serverRelativeUrl ) : void
web this The web to process
serverRelativeUrl string The server relative url of the file to checkout
return void

ConvertFolderToDocumentSet() public static method

Converts a folder with the given name as a child of the List RootFolder.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

public static ConvertFolderToDocumentSet ( this list, Folder folder ) : Folder
list this List in which the folder exists
folder Folder Folder to convert
return Folder

ConvertFolderToDocumentSet() public static method

Converts a folder with the given name as a child of the List RootFolder.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

public static ConvertFolderToDocumentSet ( this list, string folderName ) : Folder
list this List in which the folder exists
folderName string Folder name to convert
return Folder

CreateDocumentSet() public static method

Creates a new document set as a child of an existing folder, with the specified content type ID.
var setContentType = list.BestMatchContentTypeId(BuiltInContentTypeId.DocumentSet); var set1 = list.RootFolder.CreateDocumentSet("Set 1", setContentType);
public static CreateDocumentSet ( this folder, string documentSetName, ContentTypeId contentTypeId ) : Folder
folder this
documentSetName string
contentTypeId ContentTypeId Content type of the document set
return Folder

CreateFolder() public static method

Creates a folder with the given name as a child of the Web. Note it is more common to create folders within an existing Folder, such as the RootFolder of a List.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

public static CreateFolder ( this web, string folderName ) : Folder
web this Web to check for the named folder
folderName string Folder name to retrieve or create
return Folder

DoesFolderExists() public static method

Checks if a specific folder exists
public static DoesFolderExists ( this web, string serverRelativeFolderUrl ) : bool
web this The web to process
serverRelativeFolderUrl string Folder to check
return bool

EnsureFolder() public static method

Ensure that the folder structure is created. This also ensures hierarchy of folders.
public static EnsureFolder ( this web, Folder parentFolder, string folderPath ) : Folder
web this Web to be processed - can be root web or sub site
parentFolder Folder Parent folder
folderPath string Folder path
return Folder

EnsureFolder() public static method

Checks if the folder exists at the top level of the web site, and if it does not exist creates it. Note it is more common to create folders within an existing Folder, such as the RootFolder of a List.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

public static EnsureFolder ( this web, string folderName ) : Folder
web this Web to check for the named folder
folderName string Folder name to retrieve or create
return Folder

EnsureFolderPath() public static method

Check if a folder exists with the specified path (relative to the web), and if not creates it (inside a list if necessary)

If the specified path is inside an existing list, then the folder is created inside that list.

Any existing folders are traversed, and then any remaining parts of the path are created as new folders.

public static EnsureFolderPath ( this web, string webRelativeUrl ) : Folder
web this Web to check for the specified folder
webRelativeUrl string Path to the folder, relative to the web site
return Folder

FindFiles() public static method

Finds files in the web. Can be slow.
public static FindFiles ( this web, string match ) : List
web this The web to process
match string a wildcard pattern to match
return List

FolderExists() public static method

Checks if the folder exists at the top level of the web site.

Note that this only checks one level of folder (the Folders collection) and cannot accept a name with path characters.

public static FolderExists ( this web, string folderName ) : bool
web this Web to check for the named folder
folderName string Folder name to retrieve
return bool

GetFile() public static method

Gets a file in a document library.
public static GetFile ( this folder, string fileName ) : File
folder this Folder containing the target file.
fileName string File name.
return System.IO.File

GetFileAsString() public static method

Returns a file as string
public static GetFileAsString ( this web, string serverRelativeUrl ) : string
web this The Web to process
serverRelativeUrl string The server relative url to the file
return string

PublishFile() public static method

Publishes a file existing on a server url
public static PublishFile ( this web, string serverRelativeUrl, string comment ) : void
web this The web to process
serverRelativeUrl string the server relative url of the file to publish
comment string Comment recorded with the publish action
return void

ResolveSubFolder() public static method

Gets a folder with a given name in a given Microsoft.SharePoint.Client.Folder
public static ResolveSubFolder ( this folder, string folderName ) : Folder
folder this in which to search for
folderName string Name of the folder to search for
return Folder

SaveFileToLocal() public static method

Saves a remote file to a local folder
public static SaveFileToLocal ( this web, string serverRelativeUrl, string localPath, string localFileName = null, bool>.Func fileExistsCallBack = null ) : void
web this The Web to process
serverRelativeUrl string The server relative url to the file
localPath string The local folder
localFileName string The local filename. If null the filename of the file on the server will be used
fileExistsCallBack bool>.Func Optional callback function allowing to provide feedback if the file should be overwritten if it exists. The function requests a bool as return value and the string input contains the name of the file that exists.
return void

UploadFile() public static method

Uploads a file to the specified folder.
public static UploadFile ( this folder, string fileName, string localFilePath, bool overwriteIfExists ) : File
folder this Folder to upload file to.
fileName string
localFilePath string Location of the file to be uploaded.
overwriteIfExists bool true (default) to overwite existing files
return System.IO.File

UploadFileWebDav() public static method

Uploads a file to the specified folder by saving the binary directly (via webdav).
public static UploadFileWebDav ( this folder, string fileName, string localFilePath, bool overwriteIfExists ) : File
folder this Folder to upload file to.
fileName string
localFilePath string Location of the file to be uploaded.
overwriteIfExists bool true (default) to overwite existing files
return System.IO.File

VerifyIfUploadRequired() public static method

Used to compare the server file to the local file. This enables users with faster download speeds but slow upload speeds to evaluate if the server file should be overwritten.
public static VerifyIfUploadRequired ( this serverFile, Stream localStream ) : bool
serverFile this File located on the server.
localStream Stream Stream to validate against.
return bool

VerifyIfUploadRequired() public static method

Used to compare the server file to the local file. This enables users with faster download speeds but slow upload speeds to evaluate if the server file should be overwritten.
public static VerifyIfUploadRequired ( this serverFile, string localFile ) : bool
serverFile this File located on the server.
localFile string File to validate against.
return bool