本文整理汇总了C#中SPWeb.GetFile方法的典型用法代码示例。如果您正苦于以下问题:C# SPWeb.GetFile方法的具体用法?C# SPWeb.GetFile怎么用?C# SPWeb.GetFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPWeb
的用法示例。
在下文中一共展示了SPWeb.GetFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteToLog
internal static void WriteToLog(SPWeb web, string message)
{
ASCIIEncoding enc = new ASCIIEncoding();
UnicodeEncoding uniEncoding = new UnicodeEncoding();
string errors = message;
SPFile files = web.GetFile("/" + DocumentLibraryName + "/" + LogFileName);
if (files.Exists)
{
byte[] fileContents = files.OpenBinary();
string newContents = enc.GetString(fileContents) + Environment.NewLine + errors;
files.SaveBinary(enc.GetBytes(newContents));
}
else
{
using (MemoryStream ms = new MemoryStream())
{
using (StreamWriter sw = new StreamWriter(ms, uniEncoding))
{
sw.Write(errors);
}
SPFolder LogLibraryFolder = web.Folders[DocumentLibraryName];
LogLibraryFolder.Files.Add(LogFileName, ms.ToArray(), false);
}
}
web.Update();
}
示例2: AddWebParts
/// <summary>
/// Adds new web parts to the default home page.
/// </summary>
///
private void AddWebParts(SPWeb CurrentWeb)
{
try
{
/* Retrieve an instance of the default.aspx as a SPFile object. */
this._homePage = CurrentWeb.GetFile("default.aspx");
/* Retrieve an instance of the SPLimitedWebPartManager object. */
SPLimitedWebPartManager wpm = this._homePage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
/* Create an instance ofthe AsyncWebPart1 object. */
this._asyncWP = new AsyncWP1();
this._asyncWPExists = false;
/* Loop through the web part manager to see if the web part exists. */
foreach (WebPart webPart in wpm.WebParts)
{
if (webPart.GetType().FullName == this._asyncWP.GetType().FullName)
{
_asyncWPExists = true;
break;
}
}
/* Add the web part to the page if not found on the page. */
if (this._asyncWPExists == false)
{
this._asyncWP.Title = "Asynchronous Web Part Example (SPDudes)";
this._asyncWP.ToolTip = "Asynchronous Web Part Example (SPDudes)";
wpm.AddWebPart(this._asyncWP, "left", 0);
}
}
catch (Exception ex)
{
throw;
}
}
示例3: 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;
}
示例4: EnsureFile
/// <summary>
/// Method to ensure a file in a document library. Will create if not exist.
/// </summary>
/// <param name="web">The web where the list or library is</param>
/// <param name="listTitle">The list title where to ensure the file</param>
/// <param name="file">The fileinfo containing all the information needed to create the file</param>
/// <returns>The file</returns>
public SPFile EnsureFile(SPWeb web, string listTitle, FileInfo file)
{
if (file == null)
{
throw new ArgumentNullException("file");
}
SPFile sharePointFile = null;
// Locate the list/library
var list = this.listLocator.TryGetList(web, listTitle);
// Go get the file if its url is not null
if (file.Url != null)
{
sharePointFile = web.GetFile(file.Url.ToString());
}
// If the file is not found, create it.
if (sharePointFile == null || file.Overwrite)
{
sharePointFile = list.RootFolder.Files.Add(file.FileName, file.Data, file.Overwrite);
}
return sharePointFile;
}
示例5: CreateDetailNewsPage
private void CreateDetailNewsPage(SPWeb web, SPList list)
{
var rootFolder = list.RootFolder;
var dispFormUrl = string.Format("{0}/{1}/{2}.aspx", web.ServerRelativeUrl.TrimEnd('/'), rootFolder.Url, Constants.NEWS_DISPLAYPAGE);
var dispForm = web.GetFile(dispFormUrl);
if (dispForm != null && dispForm.Exists)
dispForm.Delete(); // delete & recreate our display form
// create a new DispForm
dispForm = rootFolder.Files.Add(dispFormUrl, SPTemplateFileType.FormPage);
WebPartHelper.ProvisionWebpart(web, new WebpartPageDefinitionCollection()
{
new WebpartPageDefinition() {
PageUrl = dispForm.Url,
Title = list.Title,
Webparts = new System.Collections.Generic.List<WebpartDefinition>() {
new DefaultWP(){
Index = 0,
ZoneId = "Main",
WebpartName = "NewsDetailView.webpart",
Properties = new System.Collections.Generic.List<Property>(){
new Property(){
Name = "Title",
Value = list.Title
},
new Property(){
Name="ChromeType",
Type="chrometype",
Value="2"
}
}
}
}
},
new WebpartPageDefinition() {
PageUrl = dispForm.Url,
Title = "Other news",
Webparts = new System.Collections.Generic.List<WebpartDefinition>() {
new DefaultWP(){
Index = 2,
ZoneId = "Main",
WebpartName = "OtherNewsListView.webpart",
Properties = new System.Collections.Generic.List<Property>(){
new Property(){
Name = "Title",
Value = "Other news"
}
}
}
}
}
});
dispForm.Update();
//list.Update();
}
示例6: CopySitePage
public void CopySitePage(SPWeb web, string sourceFileName, string destinationFileName)
{
SPFile file = web.GetFile(sourceFileName);
if (!file.Exists)
{
throw new ArgumentException("Incorrect file name " + sourceFileName);
}
file.CopyTo(destinationFileName, true);
}
示例7: SetAccess
private void SetAccess(SPWeb rootWeb, string filePath)
{
SPFile file = rootWeb.GetFile(filePath);
SPListItem item = file.Item;
if (item.HasUniqueRoleAssignments)
{
item.ResetRoleInheritance();
}
}
示例8: Add_FileFromURL
public static bool Add_FileFromURL(SPWeb web, int zadanieId, SPFile file)
{
bool result = false;
string srcUrl = file.ServerRelativeUrl;
SPList list = web.Lists.TryGetList(targetList);
SPListItem item = list.GetItemById(zadanieId);
if (item != null)
{
try
{
srcUrl = web.Url + "/" + file.Url;
SPFile attachmentFile = web.GetFile(srcUrl);
//item.Attachments.Add(attachmentFile.Name, attachmentFile.OpenBinaryStream();
//FileStream fs = new FileStream(srcUrl, FileMode.Open, FileAccess.Read);
Stream fs = attachmentFile.OpenBinaryStream();
// Create a byte array of file stream length
byte[] buffer = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(buffer, 0, System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
item.Attachments.AddNow(attachmentFile.Name, buffer);
//aktualizuj informacje o załączonej fakturze
item["colBR_FakturaZalaczona"] = true;
item.SystemUpdate();
}
catch (Exception)
{
//zabezpieczenie przed zdublowaniem plików
}
}
return result;
}
示例9: UpdateMasterpageGallery
private static void UpdateMasterpageGallery(SPFeatureReceiverProperties properties, SPWeb web)
{
ArrayList arrlstMasterpageFilesToOverwrite = new ArrayList();
foreach (SPFeatureProperty p in properties.Feature.Properties)
{
if (p.Name.StartsWith("overwritemasterpagefile"))
{
arrlstMasterpageFilesToOverwrite.Add(p.Value);
}
}
using (web)
{
for (int i = 0; i < arrlstMasterpageFilesToOverwrite.Count; i++)
{
//SPFile fileMasterpage = web.Lists["Master Page Gallery"].RootFolder.Files["woodgroup_site.master"];
string strFileName = arrlstMasterpageFilesToOverwrite[i].ToString();
string strFileNameWithoutExt = Path.GetFileNameWithoutExtension(strFileName);
string strFileExt = Path.GetExtension(strFileName);
try
{
SPFile fileMasterpage = web.GetFile("_catalogs/masterpage/" + strFileName);
if (fileMasterpage != null)
{
if (fileMasterpage.CheckOutType != SPFile.SPCheckOutType.None)
{
fileMasterpage.CheckIn("checked in by feature");
}
fileMasterpage.CheckOut();
//backup file will show up in Master Page/Page Layout dropdowns so either Hide them or dont make a backup
//fileMasterpage.CopyTo(web.Url + "/_catalogs/masterpage/" + strFileNameWithoutExt + "_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + strFileExt);
string strPathNewMasterPage = properties.Definition.RootDirectory + "/MOMasterpages/" + strFileName;
if (File.Exists(strPathNewMasterPage))
{
byte[] fcontents = File.ReadAllBytes(strPathNewMasterPage);
web.GetList("/_catalogs/masterpage/").RootFolder.Files.Add(strFileName, fcontents, true);
// web.Lists["Raccolta pagine master"].RootFolder.Files.Add(strFileName, fcontents, true);
fileMasterpage.Update();
fileMasterpage.CheckIn("checked in by feature");
fileMasterpage.Publish("successfully published by feature");
fileMasterpage.Approve("approved by site feature");
}
}
}
catch
{
}
}
}
}
示例10: 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;
}
示例11: AddWebPart
public static void AddWebPart(SPWeb web, Microsoft.SharePoint.WebPartPages.WebPart webPart, string pageUrl, int zoneIndex)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
web.AllowUnsafeUpdates = true;
SPFile file = web.GetFile(pageUrl);
if (file != null)
{
using (SPLimitedWebPartManager mgr = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
if (mgr != null)
{
mgr.AddWebPart(webPart, webPart.ZoneID, zoneIndex);
web.Update();
}
}
}
});
}
示例12: AddWebParts
/// <summary>
/// Adds new web parts to the default home page.
/// </summary>
///
private void AddWebParts(SPWeb CurrentWeb)
{
try
{
/* Retrieve an instance of the default.aspx as a SPFile object. */
this._homePage = CurrentWeb.GetFile("default.aspx");
/* Retrieve an instance of the SPLimitedWebPartManager object. */
SPLimitedWebPartManager wpm = this._homePage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
/* Create an instance ofthe AsyncWebPart1 object. */
SPDudesAsyncWP.SPDudesAsyncWP _asyncWP = new SPDudesAsyncWP.SPDudesAsyncWP();
_asyncWP.Title = "Asynchronous Web Part Example (SPDudes)";
_asyncWP.ToolTip = "Asynchronous Web Part Example (SPDudes)";
wpm.AddWebPart(_asyncWP, "left", 0);
}
catch (Exception ex)
{
throw;
}
}
示例13: MoveAndSetCustomerWizardFile
private void MoveAndSetCustomerWizardFile(SPWeb web)
{
try
{
web.AllowUnsafeUpdates = true;
SPFile file = web.GetFile("Style Library/Module/CustomForms/CustomerWizard.aspx");
if (file == null) //moved already
return;
file.MoveTo("/Lists/" + CustomerList + "/CustomerWizard.aspx", true);
file.Update();
SPList list = web.Lists[CustomerList];
list.NavigateForFormsPages = true;
SPContentType ct = list.ContentTypes["ListFieldsContentType"];
ct.NewFormUrl = "/Lists/" + CustomerList + "/CustomerWizard.aspx";
ct.DisplayFormUrl = "/Lists/" + CustomerList + "/CustomerWizard.aspx";
ct.EditFormUrl = "/Lists/" + CustomerList + "/CustomerWizard.aspx";
ct.Update();
list.Update();
}
catch (Exception ex)
{
Logging.WriteToLog(SPContext.Current, ex.Message);
}
finally
{
web.AllowUnsafeUpdates = false;
}
}
示例14: RestoreDataViewInZone
private void RestoreDataViewInZone(SPWeb web, string filePath)
{
if (!File.Exists(filePath) || web == null)
{
return;
}
XmlDocument doc = new XmlDocument();
try
{
doc.Load(filePath);
}
catch (XmlException)
{
return;
}
XmlNodeList xFixupFiles = doc.DocumentElement.SelectNodes("FixupFiles/FixupFile[@DataViewInZone=\"TRUE\"]");
foreach (XmlNode xFixupFile in xFixupFiles)
{
XmlAttribute xRelativePath = xFixupFile.Attributes["RelativePath"];
if (xRelativePath == null)
{
continue;
}
string relativePath = xRelativePath.Value;
SPFile file = web.GetFile(relativePath);
if (file == null)
{
continue;
}
SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
SPLimitedWebPartCollection pageWebParts = manager.WebParts;
if (pageWebParts == null)
{
continue;
}
foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in pageWebParts)
{
DataFormWebPart dataForm = webPart as DataFormWebPart;
if (dataForm == null)
{
continue;
}
this.SubstituteGuidInZone(web, manager, dataForm, filePath);
}
}
}
示例15: RemoveMasterPage
private void RemoveMasterPage(SPWeb web, string masterpageUrl)
{
SPFile file = web.GetFile(web.ServerRelativeUrl.TrimEnd('/') + masterpageUrl);
if (file.Exists)
file.Delete();
file.Update();
}