954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

saving a file to a specific path

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:

Collapse

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?

loraine96
Newbie Poster
8 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

You can use a FileStream for this:

string filepath = "C:\\test.html";
using (FileStream output = new FileStream(filepath, FileMode.Create))
{
  provider.Export(document, output);
}
darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

Check this link

FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.CreateNew);
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
 

hi abelLazm,

I've tried your code to loraine's problem but it doesn't work.

private void AddCart_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			//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())
		using(FileStream output = new FileStream(@"C:\Teting.html", FileMode.Create))
                {
                    provider.Export(document, output);
                }
            //}
	}
aubz
Newbie Poster
1 post since May 2011
Reputation Points: 10
Solved Threads: 0
 

hi abelLazm,

I've tried your code to loraine's problem but it doesn't work.

private void AddCart_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			//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())
		using(FileStream output = new FileStream(@"C:\Teting.html", FileMode.Create))
                {
                    provider.Export(document, output);
                }
            //}
	}

what is the error it is giving???? have you added this System.IO in you application? as using System.IO;

abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
 

FileMode.CreateNew throws an exception if the file exists. You can use FileMode.Create if you are happy to overwrite an existing file.

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: