Results 1 to 2 of 2

Thread: Picking Directory

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    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();

  2. #2
    Hyperactive Member r0k3t's Avatar
    Join Date
    Dec 2005
    Location
    Cleveland
    Posts
    361

    Re: Picking Directory

    I think what you are looking for is saveFileDialog...

    Something like this maybe.

    VB Code:
    1. SaveFileDialog sfn = new SaveFileDialog();
    2.  
    3. sfn.Filter = "PDF Files (*.pdf)|*.PDF| Files (*.txt)|*.TXT";
    4. sfn.CheckFileExists = false;
    5.  
    6. if (sfn.ShowDialog() == DialogResult.OK)
    7. {
    8.      strmOut = new FileStream(sfn.FileName, FileMode.Create);
    9.      try
    10.      {
    11.            do
    12.            {
    13.                    i = strmIn.ReadByte();
    14.                    if (i != -1) strmOut.WriteByte((byte)i);
    15.             } while (i != -1);
    16.      }
    17.      catch (IOException exc)
    18.      {
    19.             Console.WriteLine(exc.Message + "File Error");
    20.      }
    21.      strmIn.Close();
    22.      strmOut.Close();
    23. }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width