сохранение файла по определенному пути - PullRequest
1 голос
/ 20 мая 2011

У меня есть код для сохранения gridview в виде HTML-файла, используя savefiledialog.я хочу сохранить его по определенному пути (без использования 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);
    }
} 

как я могу сохранить его без использованиясохранить файл?

Ответы [ 3 ]

0 голосов
/ 20 мая 2011
using (var output = new FileStream("path", FileMode.Create, FileAccess.Write))
{
    provider.Export(document, output);
}
0 голосов
/ 20 мая 2011
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);
} 
0 голосов
/ 20 мая 2011
using(StreamWriter output = new StreamWriter("path\to\your\file")) {
     provider.Export(document, output);
}

будет делать то же самое, но по определенному пути. Вы можете прочитать больше о доступе к файлам на MSDN .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...