saving a file to a specific path
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 sv开发者_StackOverflowe it without using a savefiledialog?
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.
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);
}
using (var output = new FileStream("path", FileMode.Create, FileAccess.Write))
{
provider.Export(document, output);
}
OpenFileDialog displays the specific path that you have choosen.
You could set the path of the SaveFileDialog, is not necessary to show the dialog like dialog.ShowDialog()
, you have just to set the path like dialog.Filename = "file name"
.
And replace it like :
SaveFileDialog dialog = new SavefileDialog();
dialog.FileName = "path"; // like "C:\\someFolder\\someFile.html"
You could try it
精彩评论