本文整理汇总了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");
}
}
}
示例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; }
}
}