转换为字节数组并保存到特定路径 [英] convert to byte array and save to specific path
问题描述
我想将html文件保存到特定路径,而不需要保存文件对话框.
这是我用保存文件对话框保存文件的代码:
SaveFileDialog对话框= 新建 SaveFileDialog();
dialog.DefaultExt = " ;
dialog.Filter = " ;
如果(dialog.ShowDialog()== true )
{
RadDocument文档= CreateDocument(rgvReportData);
document.LayoutMode = DocumentLayoutMode.Paged;
document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
document.Arrange(新 RectangleF(PointF.Empty,document.DesiredSize));
document.SectionDefaultPageMargin = 新 Telerik.Windows.Documents.Layout.Padding( 2 , 2 ,新 HtmlFormatProvider();
使用(流输出= dialog.OpenFile())
{
provider.Export(文档,输出);
}
}
我了解到可以将图像转换为字节数组,从而将图像保存到特定路径...
首先,如SAKryukov所说,无需转换为字节数组,尽管您可能想使用字节数组进行缓冲.SaveFileDialog
除了提供创建流的便捷方法外,不参与编写文件.摆脱1 stif
语句并更改以下内容:
使用(流输出= dialog.OpenFile()) { provider.Export(文档,输出); }
至:
使用(流输出= 新 FileStream( @" , FileMode.随便, FileAccess.随便) { provider.Export(文档,输出); }
请注意,我为文件路径使用了魔术字符串,这很不好,您需要将其替换为文件名字符串.您还需要确定所需的FileMode
和FileAccess
类型:
文件模式 [文件访问 [SaveFileDialog dialog = new SaveFileDialog(); dialog.DefaultExt = "*.html"; dialog.Filter = "WORD Document (*.html)|*.html"; if (dialog.ShowDialog() == true) { RadDocument document = CreateDocument(rgvReportData); document.LayoutMode = DocumentLayoutMode.Paged; document.Measure(RadDocument.MAX_DOCUMENT_SIZE); document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize)); document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(2, 2, 2, 2); document.SectionDefaultPageOrientation = PageOrientation.Landscape; HtmlFormatProvider provider = new HtmlFormatProvider(); using (Stream output = dialog.OpenFile()) { provider.Export(document, output); } }
i learned that i can save the image to a specific path by converting it to an array of byte...
how would i convert the html file that i created and store to a specific path?解决方案First, as SAKryukov said, there is no need to convert to a byte array, although you might like to buffer using a byte array. TheSaveFileDialog
takes no part writing the file, other than providing a convenient way to create a stream. Get rid of your 1stif
statement and change the following:
using (Stream output = dialog.OpenFile()) { provider.Export(document, output); }
to:
using (Stream output = new FileStream(@"c:\foo.html",FileMode.Whatever, FileAccess.Whatever) { provider.Export(document, output); }
Note that I''ve used a magic string for the filepath, this is bad and you need to replace it with your filename string. You also need to determine whichFileMode
andFileAccess
types you need:
FileMode[^]
FileAccess[^]
这篇关于转换为字节数组并保存到特定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!