Hii, I think it helps to u. It is in C# i hopes u can understand..
if (UploadImage.PostedFile != null)
{
string fileName = UploadText.FileName.ToString();
string[] dots = fileName.Split('.');
string fileType = "txt";
string type = dots[dots.Length - 1];
string type1 = dots[dots.Length - 1];
if (fileType.IndexOf(type) == -1)
{
UploadText.Focus();
return;
}
else
{
string UploadDescription = Description.Content;
string strUploadPath = "", strFilePath = "";
strFilePath = @"C:\\UploadTextFiles\";
string path = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString();
strUploadPath = Server.MapPath(strFilePath) + path + UploadText.FileName;
UploadText.PostedFile.SaveAs(strUploadPath);
byte[] imageSize = new byte[UploadImage.PostedFile.ContentLength];
HttpPostedFile uploadedImage = UploadImage.PostedFile;
uploadedImage.InputStream.Read(imageSize, 0, (int)UploadImage.PostedFile.ContentLength);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = @"INSERT INTO table(Cols1,Cols2) VALUES (@UploadImage,@UploadText)";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlParameter UploadedImage = new SqlParameter("@UploadImage", SqlDbType.Image, imageSize.Length);
UploadedImage.Value = imageSize;
cmd.Parameters.Add(UploadedImage);
SqlParameter UploadedText = new SqlParameter("@UploadText", SqlDbType.VarChar, 200);
UploadedText.Value = strUploadPath;
cmd.Parameters.Add(UploadedText);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
if (result > 0)
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + strImageName + " image inserted successfully')", true);
SqlDataAdapter da = new SqlDataAdapter("select * from UploadProjectDetails", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
}