HttpFileCollection hFileCollection = HttpContext.Current.Request.Files;  
     for (int i = 0; i <= hFileCollection.Count; i++)  
     {  
          HttpPostedFile hPostedFile = hFileCollection[i];  
          if (hPostedFile.ContentLength > 0)  
           {  
             Stream fs = hFileCollection[i].InputStream;  
             int ImgLength = hFileCollection[i].ContentLength;  
             string contenttype = hFileCollection[i].ContentType;  
             string filePath = Path.GetFullPath(hFileCollection[i].FileName);  
             string filename = Path.GetFileName(filePath);  
             string extension = Path.GetExtension(hFileCollection[i].FileName).ToLower();  
             byte[] BinaryData = new byte[ImgLength];  
             int n = fs.Read(BinaryData, 0, ImgLength);  
             int DrawingID = objbztDrawingMasterBLL.CreateDrawingMaster(objbztDrawingMasterCls);  
             objbztDrawingMasterCls.DfileName = filename;  
             objbztDrawingMasterCls.FileConetentType = contenttype;  
             objbztDrawingMasterCls.FileData = BinaryData;  
             if (extension == ".doc" || extension == ".docx" || extension == ".xls" || extension == ".xlsx" || extension == ".jpg" || extension == ".png" || extension == ".gif" || extension == ".pdf")  
             {  
               string cmdstr = "INSERT INTO tblDtFiles(DID,DFileName,FileConetentType,FileData) VALUES(" + DID + "," + Convert.ToString(filename) + "," + Convert.ToString(contenttype) + "," + BinaryData + ")";  
               SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, cmdstr);  
             }  
             else  
             {  
               msg.Text = "Uploaded file should be doc/xls/jpg/png/gif/pdf...!";  
             }  
         }  
     }  
Thanks & Regards
Santosh Singh






thank you so much :)
ReplyDeleteGood article
ReplyDeleteYou can submit your .net related article links on http://www.dotnettechy.com to get more traffic
good one
ReplyDeleteTreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
ReplyDeleteCheck out the best
playpen nz