?
Solved

C#  --- Can't save the edits to text file openned in notepad from a form1 button1 click event.  Help please.

Posted on 2005-03-19
5
Medium Priority
?
212 Views
Last Modified: 2010-04-16
Hi everyone,

I click a button in a form that opens a file that is selected in a checkedListBox1 in Windows notepad as follows...

private void button6_Click(object sender, System.EventArgs e)
{
      string CustonListFile = (Form1.MYCustomSymbolListsPath + (string)checkedListBox1.SelectedItem);
      System.Diagnostics.Process.Start(CustonListFile);
}

It launches notepad and the text file fine, however the problem is that although I can edit and use the functionality of the notepad and it's contents, notepad does not allow me to save or save as......the file.  It asks me to make sure the path is correct.  It shows me however that the path location is correct, because a save as dialoge shows it is saving to the corrrect folder because I can see the other files and the current open file in there etc...

How can I fix this?

Thank you in advance for your help.

Regards,

Dynotoe
0
Comment
Question by:Dynotoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 2000 total points
ID: 13583739
I double checked, and it worked fine for me.

I'd check for

* file not read-only
* youv'e rights to write to the destination directory(s)
* oddball characters in the text coming from the listbox
0
 

Author Comment

by:Dynotoe
ID: 13584061


Hi cookre,

Thanks for the quick reply.  :)

did you try to save the the notepad file after typing things into it?   hmmmm....

I checked and thee was a different method that didn't close the StreamReader sr.close();     ;(

However maybe you can answer this....

I have a lines of code...

private void CreateNewCustomSymbolListNotePadItem()
{
      string path = (Form1.MYCustomSymbolListsPath + "NewList.txt");

      // Delete the file if it exists.
      if (File.Exists(path))
      {
            MessageBox.Show("File already exists.  Save file with different name before trying again.");
            //File.Delete(path);
      }
      else
      {
            //Create file
            File.Create(path);
                  
            //Write text to file
            //FileStream fs = new FileStream();
                  
            //Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
            // Add some information to the file.
            //fs.Write(info, 0, info.Length);

            //Close FileStream
            //fs.Close();
      }
}

Anyway....2 questions if I may.........I'm new at this   :)

1)  See the messageBox line........how could I create a dialoge for this so the user can "Continue with overwite" or "Cancel" options........?

2) when I Uncomment the line...

FileStream fs = new FilStream();

and try to compile I get an access error what is this and how can I control it?

If you could show me with code I would greatly appreciate it.


Thanks again Cookre!

Best,

Dynotoe



0
 
LVL 22

Expert Comment

by:cookre
ID: 13584149
1) There's an overload to MessageBox.Show() that lets you specify buttons:
iMessageBox.Show Method ("Continue with overwrite?","File Exists!,OKCancel)

It returns OK or Cancel.


2) You need to specify a filename, open mode, and access spec.
0
 

Author Comment

by:Dynotoe
ID: 13584190
Hey cookre,

That's cool.

How do I hadle in code when the user clicks for OK or Cancel?

Dynotoe
0
 
LVL 22

Expert Comment

by:cookre
ID: 13584318
It returns the string "OK" or "Cancel"
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question