|
-
Jul 9th, 2007, 07:41 AM
#1
Thread Starter
Fanatic Member
Picking Directory
I have saved a file to my sql server. I also have the name and path stored of the original file location. When the user clicks the button, I want the user to be able select a location to store the file. Right now I have this code but it saves whatever file I have to the same location and file name. The other problem is that I don't think this code descriminates on what in the Table it downloads. I will need to add some code that selects a certain row.
Code:
SqlConnection con = new SqlConnection(blah blah);
SqlDataAdapter da = new SqlDataAdapter("Select * from Images", con);
SqlCommandBuilder MyCB = new SqlCommandBuilder(da);
DataSet ds = new DataSet("MyImages");
byte[] MyData= new byte[0];
da.Fill(ds, "MyImages");
DataRow myRow;
myRow=ds.Tables["MyImages"].Rows[0];
MyData = (byte[])myRow["imgField"];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(MyData, 0,ArraySize);
fs.Close();
-
Jul 9th, 2007, 08:57 AM
#2
Hyperactive Member
Re: Picking Directory
I think what you are looking for is saveFileDialog...
Something like this maybe.
VB Code:
SaveFileDialog sfn = new SaveFileDialog();
sfn.Filter = "PDF Files (*.pdf)|*.PDF| Files (*.txt)|*.TXT";
sfn.CheckFileExists = false;
if (sfn.ShowDialog() == DialogResult.OK)
{
strmOut = new FileStream(sfn.FileName, FileMode.Create);
try
{
do
{
i = strmIn.ReadByte();
if (i != -1) strmOut.WriteByte((byte)i);
} while (i != -1);
}
catch (IOException exc)
{
Console.WriteLine(exc.Message + "File Error");
}
strmIn.Close();
strmOut.Close();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|