ازاى اقدر ارفع ملف من جهازى الى موقع web من خلال fileupload
شكرا
ازاى اقدر ارفع ملف من جهازى الى موقع web من خلال fileupload
شكرا
السلام عليكم ورحمة الله وبركاته
الموضوع التالي به مثال مرفق ان شاء الله يفيدك
جربيه واخبرينا
ورجاء استخدام البحث قبل طرح المشاركة حتى توفري على نفسك الوقت والانتظار
تمنياتي بالتوفيق
إذا أردت أن تـجـعـلـنـي سـعـيـداً ... فـعـلـمـنـي شـيـئـاً جـديـداً
Hi
try this to save uploaded file in Folder and rename file uploaded and validate uploaded file extension
in this example i upload files in Car_Image folder in my website
check this example with server side :
if (FileUpload1.HasFile == true && FileUpload1.PostedFile != null)
{
int _size = 1024;// equal 1 mb
string _fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
if (_fileExt.ToLower() == ".gif" || _fileExt.ToLower() == ".jpg" )
{
if (FileUpload1.PostedFile.ContentLength <= _size)
{
string CarFile = Guid.NewGuid().ToString() + Path.GetExtension(FileUpload1.FileName);
FileUpload1.SaveAs(Request.PhysicalApplicationPath + "Car_Image\\" + CarFile);
}
else
{
FileUpload1.Focus();
ClientScript.RegisterStartupScript(Type.GetType("System.String"), "messagebox", "<script type=\"text/javascript\">alert('Max file size is 1 m.b');</script>");
}
}
else
{
FileUpload1.Focus();
ClientScript.RegisterStartupScript(Type.GetType("System.String"), "messagebox", "<script type=\"text/javascript\">alert('Only gif or jpg are allowed');</script>");
}
}
else
{
//-- if person not has image set default for him
}
Or try this using validation to validate upload file extensions to allow users to upload Gif or Jpeg images only:
try this example to allow user to upload file with Doc extension
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Only gif file allowed!"
ControlToValidate="ctlFileUpload"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w](.)*))+(\.gif|\.GIF)$"
Width="510px" CssClass="Validator"></asp:RegularExpressionValidator>
//-----or
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Only gif file allowed!"
ControlToValidate="ctlFileUpload"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.gif|.GIF)$"
Width="510px" CssClass="Validator"></asp:RegularExpressionValidator>
//-------or
<asp:RegularExpressionValidator ID="imgValidator" runat="server" ControlToValidate="imgUpload"
ErrorMessage="*gif or jpeg files only" ValidationExpression="^.+\.(([jJ][pP][eE]?[gG])|([gG][iI][fF]))$" />
or try this to allow user to upload doc file
<asp:RegularExpressionValidator ID="FileUpLoadValidator" runat="server" ErrorMessage="Only gif files!"
ValidationExpression=".*(\.gif|\.GIF)$" ControlToValidate="FileUpload1" Display="None">
Hope it helps you