/// <summary> /// 将文件复制到~/wwwroot/{path[0]}/../{path[n]}/{Guid.NewGuid()}.file /// </summary> /// <param name="file"></param> /// <param name="path"></param> /// <returns>返回文件名</returns> private static async Task <string> CopyFileAsync(FormFileModel file, params string[] path) { var p = new List <string>(path.Count() + 2) { wwwrootPath }; var name = Guid.NewGuid() + "." + file.ExtensionName; foreach (var item in path) { p.Add(item); } p.Add(name); using (var f = File.Create(Path.Combine(p.ToArray()))) { await file.File.CopyToAsync(f); } return(name); }
public ParsedDataSource(FormFileModel file, XmlDocument xmlDoc, XmlNode node) { File = file; XmlDoc = xmlDoc; Node = node; }
public static async Task <bool> SplitHtmlAsync(FormFileModel file, List <ContentFile> files, uint cid) { if (files == null) { return(false); } var xmlDoc = new HtmlDocument(); Stream[] scriptStreams = null; try { using (var s = file.File.OpenReadStream()) { xmlDoc.Load(s); } var nodes = xmlDoc.DocumentNode.SelectNodes("script"); if (nodes != null) { scriptStreams = new Stream[nodes.Count]; string jsPath = Path.Combine(ContentParseSettings.JsSavePath); string name = null; string path = null; HtmlNode node; for (int i = 0; i < nodes.Count; i++) { node = nodes[i]; name = Guid.NewGuid().ToString() + "." + ContentParseSettings.JsUseType; path = ContentParseSettings.FileFormat(jsPath, name); using (var stream = File.Create(path)) { using (var swriter = new StreamWriter(stream)) { await swriter.WriteAsync(node.InnerText); } } xmlDoc.DocumentNode.RemoveChild(node); files.Add(new ContentFile(jsPath, name, name, "js", GetUseType("js")) { ContentId = cid, //将js,css文件可下载选项关闭 CanDownload = false }); } var htmlPath = Path.Combine(ContentParseSettings.HtmlSavePath); name = Guid.NewGuid().ToString() + "." + ContentParseSettings.HtmlUseType; path = ContentParseSettings.FileFormat(htmlPath, name); using (var htmlStream = File.Create(path)) { xmlDoc.Save(htmlStream); } files.Add(new ContentFile(htmlPath, name, file.OriginalName, file.ExtensionName, GetUseType(file.ExtensionName)) { ContentId = cid, CanDownload = false }); } return(true); } catch (Exception) { return(false); } }