9 Replies - 18647 Views - Last Post: 13 January 2009 - 02:03 PM Rate Topic: -----

#1 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

Save a file

Posted 06 January 2009 - 02:59 AM

hi I use
	Response.ClearContent();
//			Response.ClearHeaders();
//			Response.ContentType = "application/pdf";
//			Response.AddHeader("Content-Disposition", "attachment; filename="+ reportName);
//			Response.WriteFile(reportPath + reportName);
//			Response.Flush();
//			Response.Close();
in saving a file for some reason I do not want to use it anymore is there anyway to ask the user where he or she wants to save her file??

Is This A Good Question/Topic? 0
  • +

Replies To: Save a file

#2 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Save a file

Posted 06 January 2009 - 03:06 AM

Yes!

With a SaveFileDialog
Just add a SaveFileDialog from the toolbox and insert the following code.

example:

private void button1_Click(object sender, System.EventArgs e)
{
	 Stream myStream;
	 SaveFileDialog saveFileDialog1 = new SaveFileDialog();

	 saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
	 saveFileDialog1.FilterIndex = 2;
	 saveFileDialog1.RestoreDirectory = true;

	 if(saveFileDialog1.ShowDialog() == DialogResult.OK)
	 {
		 if((myStream = saveFileDialog1.OpenFile()) != null)
		 {
			 // Code to write the stream goes here.
			 myStream.Close();
		 }
	 }
}


edit: i made it a bit cleaner and added it into a buttonclick event
hope this helps

regards

B.Ihde

This post has been edited by b.ihde: 06 January 2009 - 03:40 AM

Was This Post Helpful? 0
  • +
  • -

#3 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

Re: Save a file

Posted 06 January 2009 - 05:39 PM

im only using vs 2003 is it applicable there?
Was This Post Helpful? 0
  • +
  • -

#4 badjava  Icon User is offline

  • Lux Ex Tenebris
  • member icon

Reputation: 14
  • View blog
  • Posts: 540
  • Joined: 30-October 08

Re: Save a file

Posted 06 January 2009 - 05:45 PM

View Postoasisjoel, on 6 Jan, 2009 - 04:39 PM, said:

im only using vs 2003 is it applicable there?


Did you give it a try? Come on guys put some effort in!

mebbe not a good sign...

Quote

Two ways to solve your problem

1. Think of a solution yourself Go to www.dreamincode.net
2. Post your problem in www.dreamincode.net

This post has been edited by badjava: 06 January 2009 - 05:47 PM

Was This Post Helpful? 0
  • +
  • -

#5 oasisjoel  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 274
  • Joined: 11-September 08

Re: Save a file

Posted 06 January 2009 - 05:54 PM

I already tried before I ask if it will work, cause it doesnt work for me some of variable are not detected maybe some need to be declared

btw it is said in the error that im missing an assembly reference I dont if the error only rises in 2003 because it not that complete compare to 2005 and 2008
Was This Post Helpful? 0
  • +
  • -

#6 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Save a file

Posted 07 January 2009 - 12:42 AM

Did you added the System.IO namespace?

using System.IO;



regards

B.Ihde
EDIT: i really have to agree with BadJava about your sign..
You always should to try to solve your problem on your own at FIRST!!!

This post has been edited by b.ihde: 07 January 2009 - 12:44 AM

Was This Post Helpful? 0
  • +
  • -

#7 pidass  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-January 09

Re: Save a file

Posted 13 January 2009 - 11:44 AM

I'm getting a error with ihde's code:
Error 3 The type or namespace name 'SaveFileDialog' could not be found (are you missing a using directive or an assembly reference?)

This is a C# web application.

I don't see a SaveFileDialog item in the toolbox but when I right click it and select 'choose items' it is selected so maybe it's just not available for web applications??

Anyway around this?
Was This Post Helpful? 0
  • +
  • -

#8 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Save a file

Posted 13 January 2009 - 12:26 PM

View Postpidass, on 13 Jan, 2009 - 10:44 AM, said:

This is a C# web application.


You didnīt say that before!! :P :snap:

No there s no way to use this savefiledialog..

I didnīt create a web app before, but i m gonna look what i can find..

regards

B.Ihde
Was This Post Helpful? 0
  • +
  • -

#9 pidass  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-January 09

Re: Save a file

Posted 13 January 2009 - 12:56 PM

For anyone in the future wondering this is how you have to do it from a web app:
http://forums.asp.ne...spx?PageIndex=1



View Postb.ihde, on 13 Jan, 2009 - 11:26 AM, said:

View Postpidass, on 13 Jan, 2009 - 10:44 AM, said:

This is a C# web application.


You didnīt say that before!! :P :snap:

B.Ihde


I'm not the OP.

This post has been edited by pidass: 13 January 2009 - 12:56 PM

Was This Post Helpful? 0
  • +
  • -

#10 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Save a file

Posted 13 January 2009 - 02:03 PM

ya i figured out that too ... so i m sorry :)

Also welcome to DIC! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1