MLyons10

I would like to create a form within one of my applications that someone would be able to fill out the information and click submit and it would be sent to me. I don't know if this would have to be done via e-mail, or how else it could be taken care of. Any information and help would be greatly appreciated. Also, I would like to encrypt the data if possible. How would I go about doing this

Thanks Again for any help.
-Matt-


Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

I started putting together the UI, and used textboxes. I do not know if this was the right control, but I would be interested to know other peoples thoughts and ideas. Thanks for any help and information.

Thanks,





Re: Visual C# Express Edition How to create a form and e-mail info?

Figo Fei - MSFT

Hi,

This thread is on the topic: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=928163&SiteID=1

Thanks






Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

Hi and thank you for your help. I read through those forums, and found the information very interesting. Please correct me if I'm wrong, but it appears that by using the System.Net.Mail class I would be able to have my application send data to me via e-mail without needing to launch the users e-mail application. This would be preferable, as they will be submitting information to me and it doesn't really make sense to launch an e-mail application for that. I do have a couple of questions about this though, as I still don't quite understand what I need to do.

1) I would like to encrypt the data, how would I do this

2) I have a bunch of textboxes that the user will enter information in. How will I create a report from the data that the user enters into these textboxes that will be able to be sent to me

3) Is this code the right code I would use to do what I want Would this go in the click event

MailMessage theMailMessage = new MailMessage("from@email.com", "to@email.com");
theMailMessage.Body = "body email message here";
theMailMessage.Attachments.Add(new Attachment("pathToEmailAttachment"));
theMailMessage.Subject = "Subject here";

SmtpClient theClient = new SmtpClient("IP.Address.Of.Smtp");
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential("user@name.com", "password");
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);

4) I would like the user to be able to add attachments from their local machine if they want. How would I hand this It appears that the code above makes reference to this.

5) I would like to add a progress bar to show the user the progress of the data transfer / upload. How would I do this

6) I would also like to add a Confirmation Dialog to come up after the progress bar closes and the file is uploaded. How would I do this

Thanks Again, I greatly appreciate the assistance.




Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

I just wanted to post a follow up. I tried to add the below code to the Click Event handler (I changed the appropriate information to the e-mail address, etc. The underlined words were not recognized by Visual Studio and caused errors.

MailMessage theMailMessage = new MailMessage("from@email.com", "to@email.com");
theMailMessage.Body = "body email message here";
theMailMessage.Attachments.Add(new Attachment("pathToEmailAttachment"));
theMailMessage.Subject = "Subject here";

SmtpClient theClient = new SmtpClient("IP.Address.Of.Smtp");
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential("user@name.com", "password");
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);

Additionally, how do I link to an attachment How do I generate the body of the email from the textboxes that the user would enter data in Can I set the program to check to see if two out of 4 fields are filled out for example I have two sections for required information. I don't care what set of two fields is completed, but one set should be. I would like to launch a dialog box if no information is entered in any of these fields.

Thanks Again, any information and help would be greatly appreciated.





Re: Visual C# Express Edition How to create a form and e-mail info?

jrboddie

You need to add a

using System.Net.Mail;

The body is just a string that you would get from your textBox.Text property.  If you have more than one textbox to send, you will need to concatinate them into one string with some delimiter to separate them.

For the attachment, you need to provide a string which is a path to the file that you want to attach.

I believe that XML might be the way that a pro would use to bundle a package of information to send.

There are also classes for encrypting XML data.

 





Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

Thank you for your answer. I added the using System.Net.Mail as you said and removed the following lines of code (Which were still giving me errors):

theMailMessage.Attachments.Add(new Attachment("pathToEmailAttachment:));

theClient.useDefaultCredentials = false;

Upon doing this I can now send the message, but it just has the default subject and body.

Your mention of sending the data is interesting, and sounds like it would make sense. I have a couple of questions though (I know, don't I always... ).

1) How would I read the XML file when I received it

2) I am not going to have a default attachment that it would connect to. I would like the user to be able to add several attachments if they wanted to. I do not want the attachments to be required. How would I do this

3) How would I get a string from the various Textbox text properties Can I do something similar to get the text entered in one of the textboxes and use it as part of the subject

4) Can I format the text in some sort of report so that it will be easy to read when I receive it

Thanks Again for all of your help. Any information and help is greatly appreciated.





Re: Visual C# Express Edition How to create a form and e-mail info?

jrboddie

Answer #1: There are a bunch of classes for reading and writing XML. On the receiving end, you would probably want to write a program for decoding it. Maybe something to work on after you have the basic functions working.

Answer #2: Somehow your program needs to know how many attachments it wants to send and the paths to them. Then you would invoke the

theMailMessage.Attachments.Add("path");

as many times as required.

Answer #3: Here is some example code for building a string that contains the contents of three textBoxes. The information in the boxes are separated by lines that say "Header 1", "Header 2" etc. You can make it anything you want.

(I left out some of the code you will need to send this as email.)

MailMessage theMailMessage = new MailMessage("from@email.com", "to@email.com");

//Build body of text

string message = "Header 1" + Environment.NewLine;

message += textBox1.Text+ Environment.NewLine;

string message = "Header 2" + Environment.NewLine;

message += textBox2.Text+ Environment.NewLine;

string message = "Header 3" + Environment.NewLine;

message += textBox2.Text+ Environment.NewLine;

//Set the property of the message body

theMailMessage.Body = message;

Answer #4: The code above is a simple format of your textBox data. You have the choice of formating it in your sending program or by a program on the receiving end.





Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

Hello and thank you very much for your response. I now have it working and sending the date properly (Though not formated, but that isn't a necessity at this point in time).

I do really need to be able to encrypt the information I am sending. I have had a very difficult time in trying to discern how to do this however. How would I encrypt the information being sent in the e-mail How would I decrypt it when I received the information Any information and help would be greatly appreciated, as I am really unsure how to do this or where to begin. Security is very important to me, so I want to make sure that it is done correctly.

Thank you very much for your help and any information anyone can give me.





Re: Visual C# Express Edition How to create a form and e-mail info?

jrboddie

I would start by formatting the data that you want to send from your program into an XML document. Then I would use the routine described here: http://msdn2.microsoft.com/en-us/library/ms229746.aspx to encrypt the elements of the XML document that you want to secure.

On the receiving end I would use the routing described here: http://msdn2.microsoft.com/en-us/library/ms229919.aspx

I have never used these encryption/decription classes but the documentation seems straightforward.

I have made some XML based programs though. The book Beginning Visual C# 2005 Express Edition by Peter Wright, Apress has a pretty good chapter on working with XML files. You could Google "XML tutorial" to get a handle on what XML is all about and begin to formulate what you need your XML document to look like.





Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

Thank you very much, I will read through this and see if I can't get this up and working properly. I greatly appreciate all of your help. I am a bit concerned that I may make an error and the information will end up not being encrypted. I look forward to reading these articles though and am sure that I can get things going in the right direction.

Also, all the information is being sent to the e-mail properly, with the exception of one field, and I can't for the life of me figure out what the problem is. I have a number of textBoxes, and maskedTextBoxes, but one of the maskedTextBoxes (Ironically the one in the middle), sends the data like this:

System.Windows.Forms.MaskedTextBox, Text: (___) ___-____

I have several maskedTextBoxes that are formated in the same way (As phone numbers), and even copied and pasted the maskedTextBox from another one that works properly, and I still get the same problem... Does anyone have any idea what this problem could be and how I might be able to fix it Any help would be greatly appreciated.

Thanks Again,




Re: Visual C# Express Edition How to create a form and e-mail info?

jrboddie

Can you post a bit of the code for this textBox





Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

Sure. There is no code in this maskedTextBox's EventArgs. I have this setup as three different strings called message1, message2, and message3 so that I can pull the data a couple of different ways.

Here is the code for one of the maskedTextBox's that works O.K.:

message1 += maskedTextBox4.Text + Environment.NewLine;

Here is the code for the maskedTextBox that is giving me this error:

message2 += maskedTextBox5 + Environment.NewLine;

This is the only maskedTextBox in the message2 string, but I don't know why it wouldn't work, all the other ones work. I have maskedTextBoxes in the message1 and message3 strings as well, and they are working as expected.

I hope this helps, if not, please let me know what else you might need and I will try to put it together for you.

Thanks Again for all of your help, it is greatly appreciated.





Re: Visual C# Express Edition How to create a form and e-mail info?

jrboddie

You are missing a .Text property on the message2 line.

Your line for message2 should read:

message2 += maskedTextBox5.Text +Environment.NewLine;

Also, of course, if this is the only string (or the first string in message2, you should just use '=' and not '+='.

--------------

On the xml front, I have written a simple program that takes the contents of three textBoxes and formats them into an xml document which is written to a file C:\test.xml

You can read this file with notepad just to see what it looks like. The next step is to do the encryption on the file and then send it.

Anyway, for your study...

private void button1_Click(object sender, EventArgs e)

{

//Format xml file

XmlWriterSettings settings = new XmlWriterSettings();

settings.Indent = true;

XmlWriter writer = XmlWriter.Create(@"C:\test.xml",settings);

writer.WriteStartDocument();

writer.WriteStartElement("Data");

writer.WriteElementString("Name", textBox1.Text);

writer.WriteElementString("Address", textBox2.Text);

writer.WriteElementString("Email", textBox3.Text);

writer.WriteEndElement();

writer.WriteEndDocument();

writer.Flush();

writer.Close();

}

You need to add a using System.Xml; directive for this to work.





Re: Visual C# Express Edition How to create a form and e-mail info?

MLyons10

Thank you very much, I was staring at that code so much I thought I was going to go cross-eyed, and I still missed such a glaring mistake... I appreciate you're catching it for me...

I will take a look at the code you posted for xml, and greatly appreciate your sharing it with me. I want to read through the articles you posted earlier first though so that I understand everything. Would this code replace the code I have now that pull the text out of the text boxes and generates the e-mail, or would I add the xml code to that

Also, How would I format the text in code With the current setup I imagine that would make sense, but with the xml setup it might make more sense to format with the program that would be decrypting the xml file right Would I send the xml file as an attachment I guess I'll need to add the attachment code back in.

Thanks Again, I greatly appreciate all of your help.