473,763 Members | 5,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 15 '05 #1
2 1825
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 <cc****@q5syste ms.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.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

Nov 15 '05 #2
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!
Nov 15 '05 #3

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

Similar topics

3
2999
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 Connection object (OleDBConnection) will not Open (conIncident.Open) given the following situation: 1. Program is loaded and connection is established to Access database on C:
3
360
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 (*.mdb)|*.mdb|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) DataBaseLocation.Text = openFileDialog.FileName;
4
8008
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 Explorer i am getting error saying that cannot delete that folder as some process is using it. After that i selected a file from the same folder in OpenFileDialog. When i tried to delete the folder after selecting the file also it is giving the...
8
6042
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
2342
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 InitialDirectory will cause the dialog to show files in that directory. However, any further times that the dialog is displayed, the directory that is shown will always be the one initially used regardless of the RestoreDirectory setting. This appears to be...
6
3020
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 property for ".dat" files at first time, it works. When I try to use openfiledialog to set different InitialDirectory an different Filter property for ".txt" files at second time, I got frozen window. Even I added code to dispose openfiledialog after...
3
3469
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 extension of the file, so i no longer need the openfiledialog, thus i am using openfiledialog1.reset() method to reset it. (i have also tried openfiledialog.dispose() with no results) The problem i am encountering is that the folder in which the...
8
6097
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 only the files I want to see appear in the file list box. When I change the filter to one of the other filters, all the files in the list disappear. If I then manually type a filter into the "Filename" textbox, then the files appear and the filter...
2
4718
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 the inital directory where the .resource file resides. What I am trying to do is get the location of my database and save it to string format in my resource file (un-embedded). When I go to save this information to my .resouce file it creates...
0
2182
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 (http://www.codeproject.com/KB/dialog/FileDialogExtender.aspx) ) and allows the user to select the viewing method before opening the dialog to show a file directory. The following event is assigned to a button on my form which, when prompted, displays the dialog. public...
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.