C# 将文件保存到特定路径
我有使用savefiledialog将gridview保存为html文件的代码。我想将其保存到特定路径(不使用savefiledialog)。。。我该怎么做 这是我的密码:C# 将文件保存到特定路径,c#,.net,file,autosave,C#,.net,File,Autosave,我有使用savefiledialog将gridview保存为html文件的代码。我想将其保存到特定路径(不使用savefiledialog)。。。我该怎么做 这是我的密码: SaveFileDialog dialog = new SaveFileDialog(); dialog.DefaultExt = "*.html"; dialog.Filter = "WORD Document (*.html)|*.html"; if (dialog.ShowDialog() == true) {
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);
}
}
如何在不使用savefiledialog的情况下对其进行sve
using(StreamWriter output = new StreamWriter("path\to\your\file")) {
provider.Export(document, output);
}
将执行相同的操作,但要执行特定的路径。您可以使用(var output=new FileStream(“path”,FileMode.Create,FileAccess.Write))阅读更多信息。)
{
提供者。导出(文档、输出);
}
谢谢minitech,但它没有工作。我尝试了以下方法:使用(StreamWriter output=newstreamwriter(@“C:\myreport.html”){provider.Export(document,output);},错误是:无法从system.io.StreamWriter转换为system.io.stream。provider.export接受文档和流式处理,是否确定?StreamWriter从Stream继承。不过,你可以试试显式演员阵容。谢谢你,里奇,但没用。Export()接受流作为第二个参数。@lorane96-很简单。更新以提供流。@RitchMelton您能告诉我为什么不将数据保存到特定路径string FILE=@“F:\\”+textBox1.Text代码>System.IO.File.writeAllines(文件+“.txt”,内容)代码>您是否看到任何错误?如果是的话,你能提到你看到的错误吗
String fileName = "youfilename.html"; // give the full path if required
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();
Stream output = File.Open(filename, FileMode.Open, FileAccess.ReadWrite);
provider.Export(document, output);
}