473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.writeXML
("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
Nov 15 '05 #1
2 1808
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)paldino=At-exisconsulting'dot|com

On Mon, 29 Sep 2003 10:08:33 -0700, Cory <cc****@q5systems.com> wrote:
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.writeXML
("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

Nov 15 '05 #2
This is the code in question

//browse button
private void cmdBrowse_Click(object sender, System.EventArgs e)
{
if(openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
txtFileName.Text=openFileDialog1.FileName;
}
}
//upload button
private void button1_Click(object sender, System.EventArgs e)
{
String fileName = txtFileName.Text;

if(fileName.Equals(""))
{
MessageBox.Show("File Name cannot be blank");
txtFileName.Select();
txtFileName.Focus();
}
else
{

//Get the fileData
string fileData="";
FileInfo fi= new FileInfo(fileName);
FileStream fs=fi.OpenRead();
int nBytes=(int)fi.Length;
byte[] ByteArray=new byte[nBytes];
int nBytesRead=fs.Read(ByteArray, 0, nBytes);
fs.Close();
fileData=Convert.ToBase64String(ByteArray);
CSupFile mySupFile=new CSupFile();
mySupFile.setAuditID(auditId);
mySupFile.setAuditDate(auditdate);
mySupFile.setQuestionID(questionId);
mySupFile.setName(fileName);
mySupFile.setType("b");
mySupFile.setSupData(fileData);
if(mySupFile.saveFile(data)==true)
{
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=false;

try
{
DataView vueAudits = new
DataView(data.dsFrom.Tables["audit_response_controls"],"","" ,
DataViewRowState.CurrentRows);

DataRowView rowAudits=vueAudits[0];

DataView vueAudit =
rowAudits.CreateChildView("audit_response_controls _audit_response_contro
l");
vueAudit.RowFilter="audit_id = " + auditID + " and audit_date='" +
auditDate + "'";

DataRowView rowAudit=vueAudit[0];
DataView
vueAuditResponses=rowAudit.CreateChildView("audit_ response_control_audit
_responses");

if(vueAuditResponses.Count>0)
{
DataRowView rowAuditResponses=vueAuditResponses[0];
DataView
vueAuditResponse=rowAuditResponses.CreateChildView ("audit_responses_audi
t_response");
vueAuditResponse.RowFilter="question_id=" + questionID;

if(vueAuditResponse.Count>0)
{
DataRowView rowQuestion=vueAuditResponse[0];
DataView
vueQuestion=rowQuestion.CreateChildView("audit_res ponse_sup_docs");

DataRowView rowSupFiles;

if(vueQuestion.Count==0)
{
rowSupFiles=vueQuestion.AddNew();
rowSupFiles.EndEdit();
}
else
{
rowSupFiles=vueQuestion[0];
}
DataView vueSupFile=rowSupFiles.CreateChildView("sup_docs_s up_doc");
DataRowView rowSupFile;

rowSupFile=vueSupFile.AddNew();
rowSupFile.EndEdit();

DataView vueFile=rowSupFile.CreateChildView("sup_doc_file") ;
DataRowView rowFile;
rowFile=vueFile.AddNew();
rowFile["name"]=name;
rowFile["type"]=type;
rowFile["data"]=supdata;
rowFile.EndEdit();
data.saveFromPocketPC();

saveSuccess=true;
}
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
return saveSuccess;
}

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


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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jody Gelowitz | last post by:
VS.NET 2002 and 2003 are installed. ..NET Framework 1.0 and 1.1 installed Program running under VisualBasic.NET 2002 with .NET Framwork 1.0 I am experiencing a problem with ADO.NET where the...
3
by: bobrad | last post by:
MAYBE SOMEBODY CAM HELP I AM USING THE FOLLOWING CODE TO GET A LOCATION OF A FILE IN A WINFORM DIALOG OpenFileDialog openFileDialog = new OpenFileDialog(); OpenFileDialog.Filter = " Access...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
8
by: e-mid | last post by:
why does not openFileDialog have closed event? i want to do something; as soon as the dialog closes. is there a way to do this?
1
by: Johann Blake | last post by:
A number of posts have indicated developers having problem getting an OpenFileDialog to startup in a specific directory when the dialog is shown. The first time you show the dialog, the...
6
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter...
3
by: juststarter | last post by:
Hello all, I am using an openFileDialog box to select a file (in order to insert it in a database). When the file is selected i am filling a few textboxes with the actual path, filename and...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
2
by: MikeY | last post by:
Hi everyone, I"m having a problem with the OpenFileDialog() changing my path to save to my .resources file. I'm a bit baffled why this is happening, even when I set the OpenFileDialog back to...
0
by: mbewers1 | last post by:
Hi I'm having a problem trying to get a customised OpenFileDialog() to fulfil my requirements. The code for this custom-built dialog has been taken from another site...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.