protected void blgBtn_Click(object sender, EventArgs e) { string fileName = blgFile.FileName; string filePath = blgFile.PostedFile.FileName; int fileLength = blgFile.PostedFile.ContentLength; blgFile.SaveAs(Server.MapPath("~/TextFiles/Blogs") + fileName); byte[] imageBytes = new byte[fileLength]; blgFile.PostedFile.InputStream.Read(imageBytes, 0, fileLength); if (System.IO.File.Exists(filePath)) { int counter = 2; while (System.IO.File.Exists(filePath)) { // if a file with this name already exists, // prefix the filename with a number. string tempfileName = counter.ToString() + fileName; filePath = filePath + tempfileName; counter++; } cmd = new SqlCommand("AddImg", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] prms = new SqlParameter[5]; //cmd.Parameters.AddWithValue("BlogName",blgTb.Text); cmd.Parameters.AddWithValue("BlogPath", blgFile.ToString()); //cmd.Parameters.AddWithValue("BlogFile",imageBytes); cmd.Parameters.AddWithValue("Sequence", int.Parse(Seq.Text)); cmd.Parameters.AddWithValue("Page", int.Parse(blgPage.Text)); cmd.Parameters.AddWithValue("Date", DateTime.Parse(dtpCalendar.Text)); cmd.Parameters.AddWithValue("Comment", blgComment.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close();
using System.IO; string FileChk = Server.MapPath("~/TextFiles/Blogs") + fileName; if (File.Exists(FileChk )) { //then file is exist }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)