本文整理汇总了C#中IFileSystem.WriteFile方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.WriteFile方法的具体用法?C# IFileSystem.WriteFile怎么用?C# IFileSystem.WriteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.WriteFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveTextFileContents
public static string SaveTextFileContents(IFileSystem fs, string filePath, string text)
{
// write the content to the file
fs.WriteFile(filePath, new MemoryStream(Encoding.UTF8.GetBytes(text)));
// return the public URL
string publicUrl = null;
var webAccessible = fs as IWebAccessible;
if (webAccessible != null)
publicUrl = webAccessible.GetPublicURL(filePath);
return publicUrl;
}
示例2: UploadWholeFile
// Upload entire file
private IEnumerable<FilesStatus> UploadWholeFile(HttpContext context, IFileSystem fs, SelectionUtility selection)
{
for (int i = 0; i < context.Request.Files.Count; i++)
{
var file = context.Request.Files[i];
var fileName = Path.GetFileName(file.FileName);
var virtualPath = Url.Combine(((IFileSystemNode)selection.SelectedItem).LocalUrl, fileName);
fs.WriteFile(virtualPath, file.InputStream);
yield return new FilesStatus(virtualPath, file.ContentLength);
}
}
示例3: CopyFilesRecursively
public static void CopyFilesRecursively(DirectoryInfo source, string targetVirtualPath, IFileSystem fs)
{
foreach (DirectoryInfo dir in source.GetDirectories())
{
string newDirVirtualPath = Path.Combine(targetVirtualPath, dir.Name);
fs.CreateDirectory(newDirVirtualPath);
CopyFilesRecursively(dir, newDirVirtualPath, fs);
}
foreach (FileInfo file in source.GetFiles())
{
fs.WriteFile(Path.Combine(targetVirtualPath, file.Name), file.OpenRead());
}
}
示例4: Import
public void Import(IFileSystem fs, Attachment a)
{
if (a.HasContents)
{
string path = a.Url;
if(!fs.DirectoryExists(Path.GetDirectoryName(path)))
{
fs.CreateDirectory(Path.GetDirectoryName(path));
}
var memoryStream = new MemoryStream(a.FileContents);
fs.WriteFile(path, memoryStream);
}
}
示例5: OnInit
protected override void OnInit(EventArgs e)
{
FS = Engine.Resolve<IFileSystem>();
Config = Engine.Resolve<ConfigurationManagerWrapper>().Sections.Management;
Register.JQueryUi(Page);
var selected = Selection.SelectedItem;
if (IsPostBack && !string.IsNullOrEmpty(inputFile.PostedFile.FileName))
{
string uploadFolder = Request["inputLocation"];
if(!IsAvailable(uploadFolder))
throw new N2Exception("Cannot upload to " + Server.HtmlEncode(uploadFolder));
string fileName = System.IO.Path.GetFileName(inputFile.PostedFile.FileName);
string filePath = Url.Combine(uploadFolder, fileName);
FS.WriteFile(filePath, inputFile.PostedFile.InputStream);
ClientScript.RegisterStartupScript(typeof(Tree), "select", "updateOpenerWithUrlAndClose('" + ResolveUrl(filePath) + "');", true);
}
else if (Request["location"] == "files" || Request["location"] == "filesselection")
{
IHost host = Engine.Resolve<IHost>();
HierarchyNode<ContentItem> root = new HierarchyNode<ContentItem>(Engine.Persister.Get(host.DefaultSite.RootItemID));
var selectionTrail = new List<ContentItem>();
if (selected is AbstractNode)
{
selectionTrail = new List<ContentItem>(Find.EnumerateParents(selected, null, true));
}
else
{
TrySelectingPrevious(ref selected, ref selectionTrail);
}
foreach (string uploadFolder in Engine.EditManager.UploadFolders)
{
var dd = FS.GetDirectory(uploadFolder);
var dir = Directory.New(dd, root.Current, FS, Engine.Resolve<ImageSizeCache>());
var node = CreateDirectoryNode(FS, dir, root, selectionTrail);
root.Children.Add(node);
}
AddSiteFilesNodes(root, host.DefaultSite, selectionTrail);
foreach (var site in host.Sites)
{
if (site.StartPageID == host.DefaultSite.StartPageID)
continue;
AddSiteFilesNodes(root, site, selectionTrail);
}
siteTreeView.Nodes = root;
siteTreeView.SelectedItem = selected;
}
else
{
var filter = Engine.EditManager.GetEditorFilter(Page.User);
siteTreeView.Filter = filter;
siteTreeView.RootNode = Engine.Resolve<Navigator>().Navigate(Request["root"] ?? "/");
siteTreeView.SelectedItem = selected;
}
siteTreeView.SelectableTypes = Request["selectableTypes"];
siteTreeView.SelectableExtensions = Request["selectableExtensions"];
siteTreeView.DataBind();
base.OnInit(e);
}
示例6: OnInit
protected override void OnInit(EventArgs e)
{
FS = Engine.Resolve<IFileSystem>();
Config = Engine.Resolve<ConfigurationManagerWrapper>().Sections.Management;
Register.JQueryUi(Page);
var selected = Selection.SelectedItem;
if (IsPostBack && !string.IsNullOrEmpty(inputFile.PostedFile.FileName))
{
string uploadFolder = Request[inputLocation.UniqueID];
if(!IsAvailable(uploadFolder))
throw new N2Exception("Cannot upload to " + Server.HtmlEncode(uploadFolder));
string fileName = System.IO.Path.GetFileName(inputFile.PostedFile.FileName);
string filePath = Url.Combine(uploadFolder, fileName);
if (Engine.Config.Sections.Management.UploadFolders.IsTrusted(fileName))
{
FS.WriteFile(filePath, inputFile.PostedFile.InputStream);
}
else
{
throw new N2.Security.PermissionDeniedException("Invalid file name");
}
ClientScript.RegisterStartupScript(typeof(Tree), "select", "updateOpenerWithUrlAndClose('" + ResolveUrl(filePath) + "');", true);
}
else if (Request["location"] == "files" || Request["location"] == "filesselection")
{
IHost host = Engine.Resolve<IHost>();
HierarchyNode<ContentItem> root = new HierarchyNode<ContentItem>(Engine.Persister.Get(host.DefaultSite.RootItemID));
var selectionTrail = new List<ContentItem>();
if (selected is AbstractNode)
{
selectionTrail = new List<ContentItem>(Find.EnumerateParents(selected, null, true));
}
else
{
TrySelectingPrevious(ref selected, ref selectionTrail);
}
foreach (var upload in Engine.Resolve<UploadFolderSource>().GetUploadFoldersForAllSites())
{
var dir = N2.Management.Files.FolderNodeProvider.CreateDirectory(upload, FS, Engine.Persister.Repository, Engine.Resolve<IDependencyInjector>());
if (!Engine.SecurityManager.IsAuthorized(dir, User))
continue;
var node = CreateDirectoryNode(FS, dir, root, selectionTrail);
root.Children.Add(node);
}
siteTreeView.Nodes = root;
siteTreeView.SelectedItem = selected;
}
else
{
var filter = Engine.EditManager.GetEditorFilter(Page.User);
siteTreeView.Filter = filter;
siteTreeView.RootNode = Engine.Resolve<Navigator>().Navigate(Request["root"] ?? "/");
siteTreeView.SelectedItem = selected;
}
siteTreeView.SelectableTypes = Request["selectableTypes"];
siteTreeView.SelectableExtensions = Request["selectableExtensions"];
siteTreeView.DataBind();
inputLocation.Value = siteTreeView.SelectedItem.Url;
base.OnInit(e);
}