Upload File On A Server. (Code For File Upload On A Server ASP.net)

Upload File on Server.

 public void upload_cv()
    {
        if ((Resume_Upload.ToString().Trim() != ""))
        {
            string UploadPath = "";
            string encry_path = "";
            string file_name = "";
            string file_extension = "";
            file_name = Resume_Upload.PostedFile.FileName.ToString();
            file_name = file_name.Substring(file_name.LastIndexOf(@"\") + 1);
            file_extension = file_name.Substring(file_name.LastIndexOf(".") + 1);
     if ((file_extension.ToString().ToUpper() != "DOC") 
|| (file_extension.ToString().ToUpper() != "PDF") || 
(file_extension.ToString().ToUpper() != "RTF") ||                  
     (file_extension.ToString().ToUpper() != "TXT"))
            {
          
                try
                {
         //Upload file on A Specific folder.

    UploadPath = Server.MapPath(Request.ApplicationPath + @"\upload\");
     
     Resume_Upload.PostedFile.SaveAs(UploadPath + file_name + "." + file_extension);
                        }
                    
               catch (Exception ex)
                    {
                        lbl_error.Text = ex.ToString();

                    }
             }
        else
        {
            lbl_error.Text = "Please Upload MS Word file(.doc) only";


        }
    }}




Just Call Above Function.On Some Event.HowEver You Can Also Make Security tricks to protect your file From hacker For that you Can Make File name Encrypted.


Enjoy !!!!!!!!!1

Prev Post                                                      All Post                                                           Next Post



Posted in |

0 comments:

Post a Comment