I have a file stored on a SQL server. I want the user to click a button and get asked where they would like to store that file and then save it there. I thought a savefiledialog would be the best but have never used it before. Currently I have this code and it saves the file but always in the same location.
id = the selected primary key in a listview
FileName = the filename stored in the SQL database
Code:SqlConnection con = new SqlConnection("Server=Darkover;uid=<username>;pwd=<strong password>;database=northwind"); SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages where DocID = ' " + id + "'", 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); String Filename; Filename = (string)myRow["FileName"]; FileStream fs = new FileStream(@"C:\temp\" + Filename, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(MyData, 0,ArraySize); fs.Close(); }




Reply With Quote