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


C# System.IO.FileStream.CopyTo方法代码示例

本文整理汇总了C#中System.IO.FileStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream.CopyTo方法的具体用法?C# System.IO.FileStream.CopyTo怎么用?C# System.IO.FileStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileStream的用法示例。


在下文中一共展示了System.IO.FileStream.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var xml = GenerateDataFromDataSource(GetData());

            using (System.IO.FileStream stream = new System.IO.FileStream(@"E:\currentdevelopment\cresa\Cresa\test.docx", System.IO.FileMode.Open))
            {
                using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
                {
                    stream.CopyTo(memStream);
                    WmlDocument wmlDoc = new WmlDocument("template1.doc", memStream);

                    bool templateError;
                    WmlDocument wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, xml, out templateError);

                    string imageid = "";
                   // using (System.IO.FileStream fs = System.IO.File.OpenRead(@"E:\currentdevelopment\cresa\Buildings_Curtis Block_.jpg"))
                  //  {

                  //      imageid= InsertPicture(wmlAssembledDoc, fs);
                  //  }

                    OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wmlAssembledDoc);

                    using (WordprocessingDocument wordDoc = streamDoc.GetWordprocessingDocument())
                    {
                        for (int i=1; i<=2;i ++)
                        {
                            using (System.IO.FileStream fs = System.IO.File.OpenRead(@"E:\currentdevelopment\cresa\Buildings_Curtis Block_.jpg"))
                            {
                                MainDocumentPart mainPart = wordDoc.MainDocumentPart;
                                ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
                                imagePart.FeedData(fs);

                                imageid = mainPart.GetIdOfPart(imagePart);
                            }
                            var el = AddImageToBody(imageid);

                            foreach (var  txt  in wordDoc.MainDocumentPart.Document.Body.Descendants<Text>().Where(x=>x.Text.StartsWith("<BUILDING_IMAGE")))
                            {
                                try
                                {
                                    txt.Parent.AppendChild(el);
                                    txt.Text = "";
                                }
                                catch { }

                               // Console.WriteLine(txt);

                            }
                           // wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(el)));
                        }

                    }

                    streamDoc.GetModifiedDocument().SaveAs("testzz.doc");
                  //  wmlAssembledDoc.SaveAs("template2.doc");

                }
            }
        }
开发者ID:irongoose,项目名称:Cresa,代码行数:60,代码来源:Program.cs

示例2: GZPost

        // GET: Home/GZPost
        public FileResult GZPost(int id = 0)
        {
            if (id <= 0)
            { return null; }
            else
            {
                string fileName = GetFilePath(id);
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.MemoryStream postMemory = new System.IO.MemoryStream();
                    using (System.IO.FileStream postFile = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
                    {
                        postFile.CopyTo(postMemory);
                        postFile.Close();
                    }
                    postMemory.Position = 0;
                    FileStreamResult model = new FileStreamResult(postMemory, "application/json");
                    Response.AppendHeader("Content-Encoding", "gzip");

                    return model;
                }
                else
                { return null; }
            }
        }
开发者ID:DMSysBG,项目名称:PostStore,代码行数:26,代码来源:HomeController.cs


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