0

Have a .net site and I am trying to get a copy of the form in html saved to the server when they are done. Problem is how do I get it to save the data onto a html document without having to write the whole thing again. I got this far when I realized this.

        string activeDir = @"c:\Code";
        DateTime time = DateTime.Now;              
        string folformat = "MMdyy";
        string filformat = "hmsMMdyy";
        string fdate = time.ToString(folformat);
        string newPath = System.IO.Path.Combine(activeDir, fdate);
        System.IO.Directory.CreateDirectory(newPath);
        string newFileName = time.ToString(filformat)+".html";
        newPath = System.IO.Path.Combine(newPath, newFileName);
        if (!System.IO.File.Exists(newPath))
        {
            TextWriter tw = new StreamWriter(newPath);
            tw.WriteLine(700linesofhtml);
        }

Is there a better way?

1 Answer 1

1

I'm not sure, what is the question, but instead of the if you could use

File.AppendAllText(string path, string content)

http://msdn.microsoft.com/en-us/library/ms143356.aspx

Sign up to request clarification or add additional context in comments.

4 Comments

I have an html form with text boxes A,B and C. How can I get the form with the values of A,B and C written to a new html file without having to rewrite the whole code.
you need to transform postback form data to "human readable" string (html file)?
Yes that is exactly what I'm trying to do.
try reading form data from Request.Form collection, so you can format it to some StringBuilder and output to file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.