将文件保存到特定路径 [英] saving a file to a specific path

查看:150
本文介绍了将文件保存到特定路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我有使用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);
	}
} 



解决方案

在最后一句中,"using":

using (Stream output = File.OpenWrite(@"C:\myreport.html")) // or whatever path.
    provider.Export(document, output); // Remember "using System.IO;"



顺便说一句,只需删除与文件保存对话框相关的所有代码即可.


hi! 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?

解决方案

In the last sentence, the "using":

using (Stream output = File.OpenWrite(@"C:\myreport.html")) // or whatever path.
    provider.Export(document, output); // Remember "using System.IO;"



By the way, just remove any code related to the file save dialog.


这篇关于将文件保存到特定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆