openFileDialog problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cory

    #1

    openFileDialog problem

    I have a very strange problem with my C# code. I trying to
    add a file to my dataset. I use a openFileDialog object to
    get my file. I put the file pathname in a textbox. Then i
    click my upload button which adds my file to the dataset
    and then writes the dataset to a XML file(ds.writeXM L
    ("test.xml");). I know the file is added to the dataset but
    it doesn't get written to the XML file. The strange thing
    is if i type the file pathname in the textbox it works
    perfect.Any help would be appreciated.

    Thanks in advance

    Cory


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: openFileDialog problem

    Cory,

    Can you show some of your code? Assuming that the dialog will update the textbox correctly, there should be no difference. Are you sure that the contents of the textbox are the same either way?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nick(d0t)paldin o=At-exisconsulting' dot|com

    On Mon, 29 Sep 2003 10:08:33 -0700, Cory <ccramm@q5syste ms.com> wrote:
    [color=blue]
    > I have a very strange problem with my C# code. I trying to
    > add a file to my dataset. I use a openFileDialog object to
    > get my file. I put the file pathname in a textbox. Then i
    > click my upload button which adds my file to the dataset
    > and then writes the dataset to a XML file(ds.writeXM L
    > ("test.xml");). I know the file is added to the dataset but
    > it doesn't get written to the XML file. The strange thing
    > is if i type the file pathname in the textbox it works
    > perfect.Any help would be appreciated.
    >
    > Thanks in advance
    >
    > Cory
    >
    >[/color]

    Comment

    • Cory Cramm

      #3
      Re: openFileDialog problem

      This is the code in question

      //browse button
      private void cmdBrowse_Click (object sender, System.EventArg s e)
      {
      if(openFileDial og1.ShowDialog( this) == DialogResult.OK )
      {
      txtFileName.Tex t=openFileDialo g1.FileName;
      }
      }


      //upload button
      private void button1_Click(o bject sender, System.EventArg s e)
      {
      String fileName = txtFileName.Tex t;

      if(fileName.Equ als(""))
      {
      MessageBox.Show ("File Name cannot be blank");
      txtFileName.Sel ect();
      txtFileName.Foc us();
      }
      else
      {

      //Get the fileData
      string fileData="";
      FileInfo fi= new FileInfo(fileNa me);
      FileStream fs=fi.OpenRead( );
      int nBytes=(int)fi. Length;
      byte[] ByteArray=new byte[nBytes];
      int nBytesRead=fs.R ead(ByteArray, 0, nBytes);
      fs.Close();
      fileData=Conver t.ToBase64Strin g(ByteArray);


      CSupFile mySupFile=new CSupFile();
      mySupFile.setAu ditID(auditId);
      mySupFile.setAu ditDate(auditda te);
      mySupFile.setQu estionID(questi onId);
      mySupFile.setNa me(fileName);
      mySupFile.setTy pe("b");
      mySupFile.setSu pData(fileData) ;
      if(mySupFile.sa veFile(data)==t rue)
      {
      this.Close();
      this.Dispose();
      }
      else
      {
      MessageBox.Show ("Supporting document could not be saved. Please try
      again.");
      }
      }
      }

      //adding the file to the dataset
      public Boolean saveFile(CData data)
      {
      Boolean saveSuccess=fal se;

      try
      {
      DataView vueAudits = new
      DataView(data.d sFrom.Tables["audit_response _controls"],"","" ,
      DataViewRowStat e.CurrentRows);

      DataRowView rowAudits=vueAu dits[0];

      DataView vueAudit =
      rowAudits.Creat eChildView("aud it_response_con trols_audit_res ponse_contro
      l");
      vueAudit.RowFil ter="audit_id = " + auditID + " and audit_date='" +
      auditDate + "'";

      DataRowView rowAudit=vueAud it[0];
      DataView
      vueAuditRespons es=rowAudit.Cre ateChildView("a udit_response_c ontrol_audit
      _responses");

      if(vueAuditResp onses.Count>0)
      {
      DataRowView rowAuditRespons es=vueAuditResp onses[0];
      DataView
      vueAuditRespons e=rowAuditRespo nses.CreateChil dView("audit_re sponses_audi
      t_response");
      vueAuditRespons e.RowFilter="qu estion_id=" + questionID;

      if(vueAuditResp onse.Count>0)
      {
      DataRowView rowQuestion=vue AuditResponse[0];
      DataView
      vueQuestion=row Question.Create ChildView("audi t_response_sup_ docs");

      DataRowView rowSupFiles;

      if(vueQuestion. Count==0)
      {
      rowSupFiles=vue Question.AddNew ();
      rowSupFiles.End Edit();
      }
      else
      {
      rowSupFiles=vue Question[0];
      }


      DataView vueSupFile=rowS upFiles.CreateC hildView("sup_d ocs_sup_doc");
      DataRowView rowSupFile;

      rowSupFile=vueS upFile.AddNew() ;
      rowSupFile.EndE dit();

      DataView vueFile=rowSupF ile.CreateChild View("sup_doc_f ile");
      DataRowView rowFile;
      rowFile=vueFile .AddNew();
      rowFile["name"]=name;
      rowFile["type"]=type;
      rowFile["data"]=supdata;
      rowFile.EndEdit ();


      data.saveFromPo cketPC();

      saveSuccess=tru e;
      }
      }
      }
      catch(Exception e)
      {
      Console.WriteLi ne(e.Message);
      }
      return saveSuccess;
      }

      //writing to xml file
      public void saveFromPocketP C()
      {
      dsFrom.WriteXml ("fromPocketPC. xml");
      }




      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...