Hello, I have some limited background in C++ and Java, though I haven't programmed in years. I'm wanting to begin programming through learning C#. I have a project plan in sight to help me learn along the way using Windows Forms and C#. I was looking for guidance here in breaking up the component pieces of what needs to be logically done along with certain things I need to research for best practices in the design.
Here is a rundown of the idea:
There is a folder on a PC (\..\Mail\Messages) that contains several XML files that are placed there by an existing application. I'd like to determine the location of the folder across different environments as it could be on any drive letter (C:\...D:\... etc..). I'd want to parse the XML files and then display their data in a Windows form with the option to change data through the GUI, delete the XML, or move the XML to a different folder (\..\Mail\Process).
The XML also has base64 encoded plain-text or HTML as an attribute that would need to be converted to ASCII to be readable in the GUI. I'd want the option to edit a certain value for only one XML or the same value for all XML, since each XML has the same skeleton with attributes but just different values. Since the data being changed may be an email address, I'd like to be able to confirm if the user enters a new address or edits an existing one that it is valid. This application doesn't need to do SMTP delivery. I may also want to build a subfolder of Mail\Messages\backup to backup the working XML files so that the user can revert any changes after they have saved them in the GUI. There could be just a few XMLs or up to hundreds in this Mail\Messages folder.
I'm using Visual Studio 2010 (C#) and Windows Forms. I'm doing some research to see how I should lay out these component parts along with some initial learning of the C# language and concepts.
If you can offer any advice for direction or references for different pieces I will need to consider to begin coding this, it would be much appreciated!
First of all, I don't really understand what is the purpose of what you are trying to make. However, lets break problem into smaller pieces and solve it one by one.
There is a folder on a PC (\..\Mail\Messages) that contains several XML files that are placed there by an existing application. I'd like to determine the location of the folder across different environments as it could be on any drive letter (C:\...D:\... etc..)
This is the first problem that you raised. Does "An existing application" here refers to your program that have been run on this PC before? What if (\..\Mail\Messages) does not exist? Will your program automatically create one?
Thanks for the feedback so far. In regards to the "existing application" and the speific folders and XML files, we can rightly assume those will do their job well and completely independent from the application I'm looking to write. The problem won't be whether the Mail\Messages folder exists, but moreso on which drive does it exist? I can determine this from certain env vars or the registry.
The biggest piece that I see for this project is the XML parsing and what/how to do things with it since I need to display certain parts of the XML in the GUI and leave other parts out and then the user an decide to edit the exposed part in the GUI for which I'd need to propogate that change back to the original XML. I'm not entirely sure what options I have yet for doing this or which is the best practice.
I've tried doing some initial testing with XmlTextReader, though I'm having problems. Once I parse/read-in the XML, I'm not sure how I should hanlde it. Do I store the attributes + values I care about in variables, an array, something else? Once the user makes a change by editing a value, it needs to be changed in the original XML. I was considering having the app create a backup/working folder with all XML files for which it would modify so that the user can revert all changes at the end if they'd like.
I've had successful testing using StreamReader, XmlTextReader, and XmlDocument and locating nodes via the Parent/Child relationship of node traversal. The XML files aren't very well formed and I have no control over that so this method works well with a given XML structure that is unlikely to change any time soon (outside of my control).
//Retrieve the XML and convert to stream
StreamReader sr = new StreamReader(@"C:\App\Mail\NoRetry\507987487.xml");
//Read the XML
XmlTextReader xr = new XmlTextReader(sr);
//Create the XML
XmlDocument MessageNewXml = new XmlDocument();
XmlNode MessageNode = MessageNewXml.FirstChild;
//Obtain the email address
DataTextbox.Text = MessageNode.FirstChild.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.FirstChild.FirstChild.FirstChild.InnerText;
The next piece I am researching is how I will want to iterate through the NoRetry folder to read in each XML, such as Directory.GetFiles(MailDir, "*.xml"). I presume there is some way to keep track of each XML by using array(s) or something similar. Once they are read in, I want to display most pieces of the XML in formated grid view (such as via the data table grid view). The user should be able to manipulate data within the GUI and I need to propagate the changes back to the XML changed (value change, delete entire XML, move the XML to another folder).
I'm not currently sure how to manage all the XML files with the future display and data manipulation for each. Any direction in the mean time while I research this would be gladly accepted :)