protected void btnUpload_Click(object sender, EventArgs e)
{
HttpPostedFile file = File1.PostedFile;
int intFileSize;
filepath = @"Upload\";
filetype = "";
intupload = 0;
if (file.FileName != "")
{
filename = GetFileName(file);
intFileSize = Convert.ToInt32(file.ContentLength);
if (intFileSize < 500000)
{
if (file.ContentType.IndexOf("text/plain") >= 0)
{
file.SaveAs(Server.MapPath(@"\Upload\" + filename));
filepath = filepath + filename;
filetype = @"text/plain";
lblMsge.Text = filename + " File uploaded";
intupload = 1;
}
********************************
private string GetFileName(HttpPostedFile file)
{
int i = 0, j = 0;
string strAttCnt;
string filename;
filename = file.FileName;
do
{
i = filename.IndexOf(@"\", j + 1);
if (i >= 0) j = i;
} while (i >= 0);
filename = filename.Substring(j + 1, filename.Length - j - 1);
conn = (string)ConfigurationSettings.AppSettings["cnStr"];
using (cn = new SqlConnection(conn))
{
using (cmd = new SqlCommand("select count(*) from tblusrsol where attach =1", cn))
{
cmd.CommandType = CommandType.Text;
cn.Open();
strAttCnt = cmd.ExecuteScalar().ToString();
cn.Close();
}
}
return strAttCnt + filename;
}
******************************************
after uploading i am saving the path on the label and after inserting it into database.