file upload in asp.net 1.1
-
hi i want to upload a file(.doc,.jpg etc..) into a web server by clicking on the browse button and selecting the file path from the local machine i have to upload the file. how can i do this (also how can i have the browse button ..so that when i will click over it it will open a dialouge box for file selection as usually in job sites where the user have to upload their cvs)i am using vb.net as code behind thanks in advance
pradip kishore
-
hi i want to upload a file(.doc,.jpg etc..) into a web server by clicking on the browse button and selecting the file path from the local machine i have to upload the file. how can i do this (also how can i have the browse button ..so that when i will click over it it will open a dialouge box for file selection as usually in job sites where the user have to upload their cvs)i am using vb.net as code behind thanks in advance
pradip kishore
Define the ID of file control as FileUpload then add a Button named as btnSubmit adn write the folowing code on the Button's onclick event private void btnSubmit_Click(object sender, System.EventArgs e) { try { if (isVaildData()) { if (FileUpload!=null) { string DestinationPath = Server.MapPath("../UpLoadFile/Images").ToString() ; string ImgName =GetUniqueId()+ System.IO.Path.GetFileName(FileUpload.PostedFile.FileName); ImgName = ImgName.Replace(" ", ""); string saveLoaction=DestinationPath+"\\"+ImgName; FileUpload.PostedFile.SaveAs(saveLoaction); Session["SavedFile"]=ImgName; btnSubmit.Enabled=false; btnRemoveFile.Enabled=true; lblMessage.Text="File :" + ImgName + " Uploaded Successfully "; lblMessage1.Text=ImgName; Session["strFileType"]=Request.QueryString["Type"].ToString().Trim(); } else lblMessage.Text="Please Browse a File."; } } catch(Exception ex) { string str=ex.Message; } } rivate Boolean isVaildData() { if (FileUpload.PostedFile.ContentLength==0) { lblMessage.Text="Please Select an valid file"; return false; } if ( FileUpload.PostedFile.FileName!="" ) { string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName.ToString()); string extension = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName); string Type = Request.QueryString["Type"].ToString(); switch(extension.ToLower()) { case ".pdf": break; case ".doc": break; case ".jpg": break; case ".gif": break; default: { lblMessage.Text="Invalid Disclosures file :-" + FileUpload.PostedFile.FileName; return false; } } } return true; } Neeraj
-
Define the ID of file control as FileUpload then add a Button named as btnSubmit adn write the folowing code on the Button's onclick event private void btnSubmit_Click(object sender, System.EventArgs e) { try { if (isVaildData()) { if (FileUpload!=null) { string DestinationPath = Server.MapPath("../UpLoadFile/Images").ToString() ; string ImgName =GetUniqueId()+ System.IO.Path.GetFileName(FileUpload.PostedFile.FileName); ImgName = ImgName.Replace(" ", ""); string saveLoaction=DestinationPath+"\\"+ImgName; FileUpload.PostedFile.SaveAs(saveLoaction); Session["SavedFile"]=ImgName; btnSubmit.Enabled=false; btnRemoveFile.Enabled=true; lblMessage.Text="File :" + ImgName + " Uploaded Successfully "; lblMessage1.Text=ImgName; Session["strFileType"]=Request.QueryString["Type"].ToString().Trim(); } else lblMessage.Text="Please Browse a File."; } } catch(Exception ex) { string str=ex.Message; } } rivate Boolean isVaildData() { if (FileUpload.PostedFile.ContentLength==0) { lblMessage.Text="Please Select an valid file"; return false; } if ( FileUpload.PostedFile.FileName!="" ) { string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName.ToString()); string extension = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName); string Type = Request.QueryString["Type"].ToString(); switch(extension.ToLower()) { case ".pdf": break; case ".doc": break; case ".jpg": break; case ".gif": break; default: { lblMessage.Text="Invalid Disclosures file :-" + FileUpload.PostedFile.FileName; return false; } } } return true; } Neeraj
-
Define the ID of file control as FileUpload then add a Button named as btnSubmit adn write the folowing code on the Button's onclick event private void btnSubmit_Click(object sender, System.EventArgs e) { try { if (isVaildData()) { if (FileUpload!=null) { string DestinationPath = Server.MapPath("../UpLoadFile/Images").ToString() ; string ImgName =GetUniqueId()+ System.IO.Path.GetFileName(FileUpload.PostedFile.FileName); ImgName = ImgName.Replace(" ", ""); string saveLoaction=DestinationPath+"\\"+ImgName; FileUpload.PostedFile.SaveAs(saveLoaction); Session["SavedFile"]=ImgName; btnSubmit.Enabled=false; btnRemoveFile.Enabled=true; lblMessage.Text="File :" + ImgName + " Uploaded Successfully "; lblMessage1.Text=ImgName; Session["strFileType"]=Request.QueryString["Type"].ToString().Trim(); } else lblMessage.Text="Please Browse a File."; } } catch(Exception ex) { string str=ex.Message; } } rivate Boolean isVaildData() { if (FileUpload.PostedFile.ContentLength==0) { lblMessage.Text="Please Select an valid file"; return false; } if ( FileUpload.PostedFile.FileName!="" ) { string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName.ToString()); string extension = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName); string Type = Request.QueryString["Type"].ToString(); switch(extension.ToLower()) { case ".pdf": break; case ".doc": break; case ".jpg": break; case ".gif": break; default: { lblMessage.Text="Invalid Disclosures file :-" + FileUpload.PostedFile.FileName; return false; } } } return true; } Neeraj
Hi Neeraj another small task for you suppose i uploaded a file and i want to give a link of it for the user on a page.so how the user link can be automatically created on a user interface when i will upload a page..?
pradip kishore