saving a file to a specific path

不问归期 提交于 2019-12-11 07:12:32

问题


i have the code for saving a gridview as an html file using a savefiledialog. i want to save it to a specific path (without using the savefiledialog)... how can i do that?

here's my code:

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

how can i sve it without using a savefiledialog?


回答1:


using(StreamWriter output = new StreamWriter("path\to\your\file")) {
     provider.Export(document, output);
}

will do the same thing, but to a specific path. You can read more on file access on MSDN.




回答2:


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



回答3:


using (var output = new FileStream("path", FileMode.Create, FileAccess.Write))
{
    provider.Export(document, output);
}


来源:https://stackoverflow.com/questions/6066910/saving-a-file-to-a-specific-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!