本文整理汇总了C#中SPWeb.GetFolder方法的典型用法代码示例。如果您正苦于以下问题:C# SPWeb.GetFolder方法的具体用法?C# SPWeb.GetFolder怎么用?C# SPWeb.GetFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPWeb
的用法示例。
在下文中一共展示了SPWeb.GetFolder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsureParentFolder
// ----------------------------------------------------------------------------------
public string EnsureParentFolder(SPWeb parentSite, string _destSiteURL)
{
_destSiteURL = parentSite.GetFile(_destSiteURL).Url;
int index = _destSiteURL.LastIndexOf("/");
string parentFolderUrl = string.Empty;
if (index > -1)
{
parentFolderUrl = _destSiteURL.Substring(0, index);
SPFolder parentFolder = parentSite.GetFolder(parentFolderUrl);
if (!parentFolder.Exists)
{
SPFolder currentFolder = parentSite.RootFolder;
foreach (string folder in parentFolderUrl.Split('/'))
{
currentFolder = currentFolder.SubFolders.Add(folder);
}
}
}
return parentFolderUrl;
}
示例2: CheckinFeatureFiles
private void CheckinFeatureFiles(SPWeb rootWeb, string folderPath)
{
// Check in all files in the specified folder so that they will be applied properly
SPFolder altStyleFolder = rootWeb.GetFolder(folderPath);
foreach (SPFile styleFile in altStyleFolder.Files)
{
CheckinFile(styleFile);
}
}
示例3: GetFolder
public static SPFolder GetFolder(SPWeb web, SPList list, string folderURL)
{
if (String.IsNullOrEmpty(folderURL))
return list.RootFolder;
string folderFullURL = folderURL.TrimStart('/');
SPFolder f = web.GetFolder(folderFullURL);
if (f.Exists)
return f;
else
return null;
}
示例4: Test1
private static void Test1(SPWeb web)
{
SPList list = web.Lists["Batch Delete Test"];
List<string> itemsId = new List<string>() {"6", "7", "5"};
SPFolder currentFolder = null;
foreach (string id in itemsId)
{
int idInt = Int32.Parse(id);
SPListItem tempItem = list.GetItemById(idInt);
if (tempItem.Folder == null) //find the first item which is not a folder
{
string folderUrl = SPUtility.GetUrlDirectory(tempItem.Url);
Console.WriteLine(string.Format("item id: {0}, folder url: {1}", id, folderUrl));
currentFolder = web.GetFolder(folderUrl);
Console.WriteLine("Got folder? " + (currentFolder == null));
if (currentFolder.UniqueId.Equals(list.RootFolder.UniqueId))
{
Console.WriteLine("Bo");
currentFolder = null;
}
break;
}
Console.WriteLine("!!");
}
Console.WriteLine("current folder is null? " + (currentFolder == null));
StringBuilder queryStr = new StringBuilder("<Where><In><FieldRef Name='ID'/><Values>");
foreach (string id in itemsId)
{
queryStr.AppendFormat("<Value Type='Integer'>{0}</Value>", id);
}
queryStr.Append("</Values></In></Where>");
SPQuery query = new SPQuery() {Query = queryStr.ToString()};
if (currentFolder != null)
{
query.Folder = currentFolder;
}
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem item in items)
{
Console.WriteLine(item.Title);
}
}
示例5: GetTransformStream
protected Stream GetTransformStream(SPWeb web)
{
SPFile transformF = web.GetFile("FDR/Faculty Data XSLT to HTML/FDR.xslt");
// This doesn't work:; transformS = transformF.OpenBinaryStream();
SPFolder folder = web.GetFolder(TransformsListName);
foreach (SPFile file in folder.Files)
{
if (file.Exists)
{
if (file.Name == TransformItemName)
{
return file.OpenBinaryStream();
}
}
}
// Perhaps raise an exception here.
return null;
}
示例6: GetDestinationList
private SPList GetDestinationList(SPWeb destinationWeb)
{
SPList destinationList = null;
SPFolder destinationFolder = destinationWeb.GetFolder(DestinationFolderUrl);
if (destinationFolder.ParentListId != Guid.Empty)
destinationList = destinationWeb.Lists.GetList(destinationFolder.ParentListId, false);
else
__ActivationProperties.LogToWorkflowHistory(SPWorkflowHistoryEventType.WorkflowError, __ActivationProperties.Web.CurrentUser, "The library does not exist", string.Empty);
return destinationList;
}
示例7: GetDestinationFolder
private SPFolder GetDestinationFolder(SPWeb destinationWeb, SPList destinationList)
{
SPFolder destinationFolder = destinationWeb.GetFolder(DestinationFolderUrl);
if (!destinationFolder.Exists)
{
// create folder
string strFolders = DestinationFolderUrl.Substring(
DestinationFolderUrl.ToLower().IndexOf(destinationList.RootFolder.ServerRelativeUrl.ToLower()) +
destinationList.RootFolder.ServerRelativeUrl.Length + 1);
string[] arrFolder = strFolders.Split('/');
for (int i = 0; i < arrFolder.Length; i++)
{
string strURLCreate = destinationList.RootFolder.ServerRelativeUrl;
for (int j = 0; j <= i; j++)
{
strURLCreate += "/" + arrFolder[j];
}
destinationWeb.Folders.Add(strURLCreate);
}
destinationFolder = destinationWeb.GetFolder(DestinationFolderUrl);
}
//In case of Forms folder
if (destinationFolder.Properties["vti_listbasetype"] == null)
{
//Error when the hidden folder of document
__ActivationProperties.LogToWorkflowHistory(SPWorkflowHistoryEventType.WorkflowError, __ActivationProperties.Web.CurrentUser, "Cannot place files in to " + DestinationFolderUrl, string.Empty);
return null;
}
return destinationFolder;
}
示例8: AddDocumentLink
public SPFile AddDocumentLink(SPWeb web, SPFolder targetFolder, string documentPath, string documentName, string documentUrl)
{
web.RequireNotNull("web");
targetFolder.RequireNotNull("targetFolder");
documentPath.RequireNotNullOrEmpty("documentPath");
documentName.RequireNotNullOrEmpty("documentName");
documentUrl.RequireNotNullOrEmpty("documentUrl");
IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
IContentTypeOperations contentTypeOps = serviceLocator.GetInstance<IContentTypeOperations>();
string contentTypeName = "Link to a Document";
var contentType = web.AvailableContentTypes[contentTypeName];
SPDocumentLibrary DocLibrary = targetFolder.DocumentLibrary;
if (null != DocLibrary)
{
bool LinkToDocumentApplied = false;
foreach (SPContentType cType in DocLibrary.ContentTypes)
{
if (cType.Name == contentTypeName)
{
LinkToDocumentApplied = true;
break;
}
}
if (!LinkToDocumentApplied)
{
contentTypeOps.AddContentTypeToList(contentType, DocLibrary);
}
}
var filePath = targetFolder.ServerRelativeUrl;
if (!string.IsNullOrEmpty(documentPath))
{
filePath += "/" + documentPath;
}
var currentFolder = web.GetFolder(filePath);
var files = currentFolder.Files;
var urlOfFile = currentFolder.Url + "/" + documentName + ".aspx";
var builder = new StringBuilder(aspxPageFormat.Length + 400);
builder.AppendFormat(aspxPageFormat, typeof(SPDocumentLibrary).Assembly.FullName);
var properties = new Hashtable();
properties["ContentTypeId"] = contentType.Id.ToString();
var file = files.Add(urlOfFile, new MemoryStream(new UTF8Encoding().GetBytes(builder.ToString())), properties, false, false);
var item = file.Item;
item["URL"] = documentUrl + ", ";
item.UpdateOverwriteVersion();
return file;
}
示例9: Copyfiles
public static void Copyfiles(SPWeb spWeb, string sourceDocumentLibraryName, string destinationDocumentLibraryName)
{
SPList sourceDocuments = spWeb.Lists[sourceDocumentLibraryName];
SPList destinationDocuments = spWeb.Lists[destinationDocumentLibraryName];
if (sourceDocuments.ItemCount > 0)
{
foreach (SPListItem currentSourceDocument in sourceDocuments.Items)
{
if (currentSourceDocument.FileSystemObjectType == SPFileSystemObjectType.Folder)
{
string relativeUrl = currentSourceDocument.File.ServerRelativeUrl;
destinationDocuments.Items.Add(destinationDocuments.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, relativeUrl);
}
else
{
CreateFolder(destinationDocuments, currentSourceDocument.File.ParentFolder);
byte[] fileBytes = currentSourceDocument.File.OpenBinary();
const bool overwriteDestinationFile = true;
//string relativeDestinationUrl = currentSourceDocument.File.ParentFolder.Name + "/" + currentSourceDocument.File.Name;
string relativeDestinationUrl = currentSourceDocument.File.ParentFolder + "/" + currentSourceDocument.File.Name;
SPFile destinationFile = ((SPDocumentLibrary)destinationDocuments).RootFolder.Files.Add(relativeDestinationUrl, fileBytes, overwriteDestinationFile);
}
}
}
SPFolder oFolder = spWeb.GetFolder(sourceDocumentLibraryName);
SPFileCollection collFile = oFolder.Files;
//Copying files from the Root folder.
CopyFiles(collFile);
// Get the sub folder collection
SPFolderCollection collFolder = oFolder.SubFolders;
EnumerateFolders(collFolder);
}
示例10: GetApprovalConfigurationTemplateList
private SPList GetApprovalConfigurationTemplateList(SPWeb web)
{
SPList list = null;
SPFolder folder = web.GetFolder(ApprovalConfigListURL);
if (folder.ParentListId != Guid.Empty)
list = web.Lists.GetList(folder.ParentListId, false);
else
__ActivationProperties.LogToWorkflowHistory(SPWorkflowHistoryEventType.WorkflowError, __ActivationProperties.Web.CurrentUser, "The approval configuration list does not exist", string.Empty);
return list;
}