Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
why the file dont created?
it is my code
C#
private void chng_OnClick(object sender, EventArgs e)
   {

       string pass = txt_pass.Text;
       string passhash = MD5Hash(pass);
       string path = Server.MapPath(".");
       StreamWriter file = new StreamWriter(path+"log.txt");

       file.WriteLine(passhash);
       file.Close();

       txt_pass.Text = "";
   }
   public static string MD5Hash(string text)
   {
       MD5 md5 = new MD5CryptoServiceProvider();

       //compute hash from the bytes of text
       md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));

       //get hash result after compute it
       byte[] result = md5.Hash;

       StringBuilder strBuilder = new StringBuilder();
       for (int i = 0; i < result.Length; i++)
       {
           //change it into 2 hexadecimal digits
           //for each byte
           strBuilder.Append(result[i].ToString("x2"));
       }

       return strBuilder.ToString();
   }
Posted
Comments
bbirajdar 19-Dec-13 1:02am    
Because you have not written the code for creating and opening the file

check google for some code samples

file.Create("D://filename.txt");

1 solution

Couple of suggestions..

1. When you create new instance of streamwriter, you can specify the file access mode. For example, open or create, append.

2. Before the file.close() method, flush the buffer i.e file.flush(). Flush will clear the buffer and write the stream to file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900