当前位置: 首页>>代码示例>>C#>>正文


C# IFileSystem.WriteFile方法代码示例

本文整理汇总了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;
        }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:12,代码来源:TextFile.cs

示例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);
            }
        }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:14,代码来源:UploadFile.ashx.cs

示例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());
     }
 }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:13,代码来源:FileSystemTests.cs

示例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);
            }
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:15,代码来源:FileAttachmentAttribute.cs

示例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);
        }
开发者ID:sale42,项目名称:n2cms,代码行数:68,代码来源:Tree.aspx.cs

示例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);
        }
开发者ID:EzyWebwerkstaden,项目名称:n2cms,代码行数:71,代码来源:Tree.aspx.cs


注:本文中的IFileSystem.WriteFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。