Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将文件保存到特定路径_C#_.net_File_Autosave - Fatal编程技术网

C# 将文件保存到特定路径

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将gridview保存为html文件的代码。我想将其保存到特定路径(不使用savefiledialog)。。。我该怎么做

这是我的密码:

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);
}