1

我有使用 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 的情况下保存它?

4

4 回答 4

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

会做同样的事情,但要特定的路径。您可以在 MSDN 上阅读有关文件访问的更多信息。

于 2011-05-20T02:41:58.720 回答
0
using (var output = new FileStream("path", FileMode.Create, FileAccess.Write))
{
    provider.Export(document, output);
}
于 2011-05-20T02:43:41.207 回答
0
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);
} 
于 2011-05-20T02:46:05.570 回答
0

OpenFileDialog 显示您选择的特定路径。您可以设置 SaveFileDialog 的路径,不需要显示对话框dialog.ShowDialog(),您只需设置路径dialog.Filename = "file name"
并将其替换为:

SaveFileDialog dialog = new SavefileDialog(); 
dialog.FileName = "path"; // like "C:\\someFolder\\someFile.html"

你可以试试

于 2021-08-07T07:59:19.170 回答