Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Download multiple Xml file

Download multiple Xml file

Scheduled Pinned Locked Moved ASP.NET
helpdatabasexml
18 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Not Active

    Maybe use something like SaveFileDialog[^] :rolleyes:


    I know the language. I've read a book. - _Madmatt

    T Offline
    T Offline
    Tash18
    wrote on last edited by
    #3

    Im using VS2003 framework1.1 Any other ideas or any other ways do please let me know.... Thanx in advance Regards, Tash

    modified on Wednesday, February 3, 2010 11:05 PM

    1 Reply Last reply
    0
    • T Tash18

      Hi guyzz.. Im developing a web application here i get datas from the user and on a button click these datas get stored in my data base now i have another button on clicking it,it retrieves all the data from the database and gets saved in my system as an XML file... the code is as follows for the button that creates an xml file...

      private void Button1_Click(object sender, System.EventArgs e)
      {
      SqlDataAdapter da = null;
      try
      {
      con = new SqlConnection();
      con.ConnectionString = ConfigurationSettings.AppSettings["DSN"];
      da = new SqlDataAdapter("select * from card_details",con);
      DataSet ds = new DataSet();
      da.Fill(ds,"card_details");
      ds.WriteXml("D:\ADIB\OutputXML.xml");
      }
      catch(SqlException ex)
      {
      throw new System.Exception ("Error -- " +ex.Message);
      }
      catch(Exception exp)
      {
      throw new System.Exception ("Error -- " +exp.Message);
      }
      finally
      {
      con.Close();
      da.Dispose();
      }
      }

      Now my issue is i need my application to create the xml file,before saving it into my system it should ask me whether to open the file or save the file so that i can specify the file name (something similar to a download window in our web browser)... please advice me... Thanx in advance.. Regards, Tash

      T Offline
      T Offline
      Tash18
      wrote on last edited by
      #4

      Any ideas or any ways do please let me know...... Regards, Tash

      1 Reply Last reply
      0
      • N Not Active

        Maybe use something like SaveFileDialog[^] :rolleyes:


        I know the language. I've read a book. - _Madmatt

        T Offline
        T Offline
        Tash18
        wrote on last edited by
        #5

        Sorry it dint work.. Im using VS2003... plz advice me... Thanx in advance.. Regards, Tash

        1 Reply Last reply
        0
        • T Tash18

          Hi guyzz.. Im developing a web application here i get datas from the user and on a button click these datas get stored in my data base now i have another button on clicking it,it retrieves all the data from the database and gets saved in my system as an XML file... the code is as follows for the button that creates an xml file...

          private void Button1_Click(object sender, System.EventArgs e)
          {
          SqlDataAdapter da = null;
          try
          {
          con = new SqlConnection();
          con.ConnectionString = ConfigurationSettings.AppSettings["DSN"];
          da = new SqlDataAdapter("select * from card_details",con);
          DataSet ds = new DataSet();
          da.Fill(ds,"card_details");
          ds.WriteXml("D:\ADIB\OutputXML.xml");
          }
          catch(SqlException ex)
          {
          throw new System.Exception ("Error -- " +ex.Message);
          }
          catch(Exception exp)
          {
          throw new System.Exception ("Error -- " +exp.Message);
          }
          finally
          {
          con.Close();
          da.Dispose();
          }
          }

          Now my issue is i need my application to create the xml file,before saving it into my system it should ask me whether to open the file or save the file so that i can specify the file name (something similar to a download window in our web browser)... please advice me... Thanx in advance.. Regards, Tash

          P Offline
          P Offline
          Palash Biswas
          wrote on last edited by
          #6

          use below code

          private void button1_Click(object sender, EventArgs e)
          {
          saveFileDialog1.FileOk += new CancelEventHandler(saveFileDialog1_FileOk);
          saveFileDialog1.ShowDialog(this);

              }
          
              void saveFileDialog1\_FileOk(object sender, CancelEventArgs e)
              {
                  SaveFileDialog ss = sender as SaveFileDialog;
          
                  SqlDataAdapter da = null;
                  try
                  {
                      con = new SqlConnection();
                      con.ConnectionString = ConfigurationSettings.AppSettings\["DSN"\];
                      da = new SqlDataAdapter("select \* from card\_details", con);
                      DataSet ds = new DataSet(); da.Fill(ds, "card\_details");
                      ds.WriteXml(ss.FileName);
                  }
                  catch (SqlException ex)
                  {
                      throw new System.Exception("Error -- " + ex.Message);
                  }
                  catch (Exception exp)
                  {
                      throw new System.Exception("Error -- " + exp.Message);
                  }
                  finally
                  {
                      con.Close(); da.Dispose();
                  }
                  
              }
          

          saveFileDialog1 is SaveFileDialog type win control.

          T 1 Reply Last reply
          0
          • P Palash Biswas

            use below code

            private void button1_Click(object sender, EventArgs e)
            {
            saveFileDialog1.FileOk += new CancelEventHandler(saveFileDialog1_FileOk);
            saveFileDialog1.ShowDialog(this);

                }
            
                void saveFileDialog1\_FileOk(object sender, CancelEventArgs e)
                {
                    SaveFileDialog ss = sender as SaveFileDialog;
            
                    SqlDataAdapter da = null;
                    try
                    {
                        con = new SqlConnection();
                        con.ConnectionString = ConfigurationSettings.AppSettings\["DSN"\];
                        da = new SqlDataAdapter("select \* from card\_details", con);
                        DataSet ds = new DataSet(); da.Fill(ds, "card\_details");
                        ds.WriteXml(ss.FileName);
                    }
                    catch (SqlException ex)
                    {
                        throw new System.Exception("Error -- " + ex.Message);
                    }
                    catch (Exception exp)
                    {
                        throw new System.Exception("Error -- " + exp.Message);
                    }
                    finally
                    {
                        con.Close(); da.Dispose();
                    }
                    
                }
            

            saveFileDialog1 is SaveFileDialog type win control.

            T Offline
            T Offline
            Tash18
            wrote on last edited by
            #7

            Hi thanx for ur reply... My problem is not solved yet... as u said when i type saveFileDialog1. i dont find "FileOk"... i dont know why... may be its because im using VS2003??? plz help me... Thanx in advance... Regards,\ Tash

            R P 2 Replies Last reply
            0
            • T Tash18

              Hi thanx for ur reply... My problem is not solved yet... as u said when i type saveFileDialog1. i dont find "FileOk"... i dont know why... may be its because im using VS2003??? plz help me... Thanx in advance... Regards,\ Tash

              R Offline
              R Offline
              Ravindra Nidhonkar
              wrote on last edited by
              #8

              Following code should solve your problem:

              Response.Clear();
              Response.ContentType = "text/plain";
              Response.WriteFile("D:\\ADIB\\OutputXML.xml");
              Response.Flush();

              1 Reply Last reply
              0
              • T Tash18

                Hi thanx for ur reply... My problem is not solved yet... as u said when i type saveFileDialog1. i dont find "FileOk"... i dont know why... may be its because im using VS2003??? plz help me... Thanx in advance... Regards,\ Tash

                P Offline
                P Offline
                Palash Biswas
                wrote on last edited by
                #9

                I wrote my code in VS 2008. Under dialog section of toolbox you can get the specified control. TRY this Code

                System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();

                saveFileDialog.Filter = "XML Files (*.xml)|*.*";

                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)

                {

                string FileName = saveFileDialog.FileName;

                if (FileName.Trim() != "")

                {

                // your Code here
                }

                }

                T 1 Reply Last reply
                0
                • P Palash Biswas

                  I wrote my code in VS 2008. Under dialog section of toolbox you can get the specified control. TRY this Code

                  System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();

                  saveFileDialog.Filter = "XML Files (*.xml)|*.*";

                  if (saveFileDialog.ShowDialog(this) == DialogResult.OK)

                  {

                  string FileName = saveFileDialog.FileName;

                  if (FileName.Trim() != "")

                  {

                  // your Code here
                  }

                  }

                  T Offline
                  T Offline
                  Tash18
                  wrote on last edited by
                  #10

                  I did as u said.. but got an error in this line --->

                  if (saveFileDialog.ShowDialog(this) == DialogResult.OK)

                  The error stated was ---> The best overloaded method match for 'System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)' has some invalid arguments Thanx in advance... Regards, Tash

                  P 1 Reply Last reply
                  0
                  • T Tash18

                    I did as u said.. but got an error in this line --->

                    if (saveFileDialog.ShowDialog(this) == DialogResult.OK)

                    The error stated was ---> The best overloaded method match for 'System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)' has some invalid arguments Thanx in advance... Regards, Tash

                    P Offline
                    P Offline
                    Palash Biswas
                    wrote on last edited by
                    #11

                    try this

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)

                    T 1 Reply Last reply
                    0
                    • P Palash Biswas

                      try this

                      if (saveFileDialog.ShowDialog() == DialogResult.OK)

                      T Offline
                      T Offline
                      Tash18
                      wrote on last edited by
                      #12

                      Hi.. now ther was no build errors but after execution.. when i click my button to create Xml file i receive the following exception ---> It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application. And the line in which this exception ocuurs -->>

                      if (saveFileDialog.ShowDialog() == DialogResult.OK)

                      thanx in advance.. Regards, Tash

                      P 1 Reply Last reply
                      0
                      • T Tash18

                        Hi.. now ther was no build errors but after execution.. when i click my button to create Xml file i receive the following exception ---> It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application. And the line in which this exception ocuurs -->>

                        if (saveFileDialog.ShowDialog() == DialogResult.OK)

                        thanx in advance.. Regards, Tash

                        P Offline
                        P Offline
                        Palash Biswas
                        wrote on last edited by
                        #13

                        I think you are not use win form application . Is that true if it is then you can't do it using previous procedure.Please use a Custom pop up to do this.

                        T 1 Reply Last reply
                        0
                        • P Palash Biswas

                          I think you are not use win form application . Is that true if it is then you can't do it using previous procedure.Please use a Custom pop up to do this.

                          T Offline
                          T Offline
                          Tash18
                          wrote on last edited by
                          #14

                          Ohh no.. so what am i supposed 2 do??? any idea??? regards, tash

                          P 2 Replies Last reply
                          0
                          • T Tash18

                            Ohh no.. so what am i supposed 2 do??? any idea??? regards, tash

                            P Offline
                            P Offline
                            Palash Biswas
                            wrote on last edited by
                            #15

                            This will help you much , I think it works fine :-D

                            Response.ContentType = "text/xml";
                            Response.AppendHeader("Content-Disposition", "attachment; filename=mmm.xml");
                            Response.TransmitFile(Server.MapPath("~/images/mmm.jpg"));
                            SqlDataAdapter da = null;
                            try
                            {
                            con = new SqlConnection();
                            con.ConnectionString = ConfigurationSettings.AppSettings["DSN"];
                            da = new SqlDataAdapter("select * from card_details", con);
                            DataSet ds = new DataSet(); da.Fill(ds, "card_details");
                            ds.WriteXml(Response.OutputStream);
                            Response.End();
                            }
                            catch (SqlException ex)
                            {
                            throw new System.Exception("Error -- " + ex.Message);
                            }
                            catch (Exception exp)
                            {
                            throw new System.Exception("Error -- " + exp.Message);
                            }
                            finally
                            {
                            con.Close(); da.Dispose();
                            }

                            modified on Thursday, February 4, 2010 6:01 AM

                            P 1 Reply Last reply
                            0
                            • P Palash Biswas

                              This will help you much , I think it works fine :-D

                              Response.ContentType = "text/xml";
                              Response.AppendHeader("Content-Disposition", "attachment; filename=mmm.xml");
                              Response.TransmitFile(Server.MapPath("~/images/mmm.jpg"));
                              SqlDataAdapter da = null;
                              try
                              {
                              con = new SqlConnection();
                              con.ConnectionString = ConfigurationSettings.AppSettings["DSN"];
                              da = new SqlDataAdapter("select * from card_details", con);
                              DataSet ds = new DataSet(); da.Fill(ds, "card_details");
                              ds.WriteXml(Response.OutputStream);
                              Response.End();
                              }
                              catch (SqlException ex)
                              {
                              throw new System.Exception("Error -- " + ex.Message);
                              }
                              catch (Exception exp)
                              {
                              throw new System.Exception("Error -- " + exp.Message);
                              }
                              finally
                              {
                              con.Close(); da.Dispose();
                              }

                              modified on Thursday, February 4, 2010 6:01 AM

                              P Offline
                              P Offline
                              Palash Biswas
                              wrote on last edited by
                              #16

                              Try this i think it will help you; Response.ContentType = "text/xml"; Response.AppendHeader("Content-Disposition", "attachment; filename=mmm.xml"); Response.TransmitFile(Server.MapPath("~/images/sailbig.jpg")); SqlDataAdapter da = null; try { con = new SqlConnection(); con.ConnectionString = ConfigurationSettings.AppSettings["DSN"]; da = new SqlDataAdapter("select * from card_details", con); DataSet ds = new DataSet(); da.Fill(ds, "card_details"); ds.WriteXml(Response.OutputStream); Response.End(); } catch (SqlException ex) { throw new System.Exception("Error -- " + ex.Message); } catch (Exception exp) { throw new System.Exception("Error -- " + exp.Message); } finally { con.Close(); da.Dispose(); } }

                              1 Reply Last reply
                              0
                              • T Tash18

                                Hi guyzz.. Im developing a web application here i get datas from the user and on a button click these datas get stored in my data base now i have another button on clicking it,it retrieves all the data from the database and gets saved in my system as an XML file... the code is as follows for the button that creates an xml file...

                                private void Button1_Click(object sender, System.EventArgs e)
                                {
                                SqlDataAdapter da = null;
                                try
                                {
                                con = new SqlConnection();
                                con.ConnectionString = ConfigurationSettings.AppSettings["DSN"];
                                da = new SqlDataAdapter("select * from card_details",con);
                                DataSet ds = new DataSet();
                                da.Fill(ds,"card_details");
                                ds.WriteXml("D:\ADIB\OutputXML.xml");
                                }
                                catch(SqlException ex)
                                {
                                throw new System.Exception ("Error -- " +ex.Message);
                                }
                                catch(Exception exp)
                                {
                                throw new System.Exception ("Error -- " +exp.Message);
                                }
                                finally
                                {
                                con.Close();
                                da.Dispose();
                                }
                                }

                                Now my issue is i need my application to create the xml file,before saving it into my system it should ask me whether to open the file or save the file so that i can specify the file name (something similar to a download window in our web browser)... please advice me... Thanx in advance.. Regards, Tash

                                P Offline
                                P Offline
                                Palash Biswas
                                wrote on last edited by
                                #17

                                I think , The below code will help you much

                                Response.ContentType = "text/xml";
                                Response.AppendHeader("Content-Disposition", "attachment; filename=mmm.xml");
                                Response.TransmitFile(Server.MapPath("~/images/mmm.jpg"));
                                SqlDataAdapter da = null;
                                try
                                {
                                con = new SqlConnection();
                                con.ConnectionString = ConfigurationSettings.AppSettings["DSN"];
                                da = new SqlDataAdapter("select * from card_details", con);
                                DataSet ds = new DataSet(); da.Fill(ds, "card_details");
                                ds.WriteXml(Response.OutputStream);
                                Response.End();
                                }
                                catch (SqlException ex)
                                {
                                throw new System.Exception("Error -- " + ex.Message);
                                }
                                catch (Exception exp)
                                {
                                throw new System.Exception("Error -- " + exp.Message);
                                }
                                finally
                                {
                                con.Close(); da.Dispose();
                                }

                                1 Reply Last reply
                                0
                                • T Tash18

                                  Ohh no.. so what am i supposed 2 do??? any idea??? regards, tash

                                  P Offline
                                  P Offline
                                  Palash Biswas
                                  wrote on last edited by
                                  #18

                                  use ...

                                  Response.ContentType = "text/xml";
                                  Response.AppendHeader("Content-Disposition", "attachment; filename=mmm.xml");
                                  Response.TransmitFile(Server.MapPath("~/images/mmm.jpg"));
                                  SqlDataAdapter da = null;
                                  try
                                  {
                                  con = new SqlConnection();
                                  con.ConnectionString = ConfigurationSettings.AppSettings["DSN"];
                                  da = new SqlDataAdapter("select * from card_details", con);
                                  DataSet ds = new DataSet(); da.Fill(ds, "card_details");
                                  ds.WriteXml(Response.OutputStream);
                                  Response.End();
                                  }
                                  catch (SqlException ex)
                                  {
                                  throw new System.Exception("Error -- " + ex.Message);
                                  }
                                  catch (Exception exp)
                                  {
                                  throw new System.Exception("Error -- " + exp.Message);
                                  }
                                  finally
                                  {
                                  con.Close(); da.Dispose();
                                  }

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups