asp.net
Check if HttpContext.Current.Request.Files[“filex”] has file
I am working on an ASP .net webpage which receives a form which is posted to it. The posted form has three as well. filename = uploadFile(HttpContext.Current.Request.Files["file1"], path); This is the code through which i upload a file to my server. And this is the code of the function. public string uploadFile(HttpPostedFile file, string dest) { string filename = file.FileName; string path = Server.MapPath(dest); String extension = Path.GetExtension(file.FileName); filename = filename.Replace(extension, ""); filename = filename.Replace(".", ""); filename = System.DateTime.Now.ToString("ddMMyyyyhhmmss") + filename + extension; string savepath = path + "/" + filename; file.SaveAs(savepath); return filename; } The problem is I am not able to check if file1 from the posted form actually has file. Is it possible?
Use the FileUpload control in conjunction with the HasFile property: FileUpload.HasFile Property If you have to do it that way, you can simply check if the ContentLength is greater than zero.
Related Links
Is it possible to use Ajax update panel without using trigger?
Lucene Interlacing Search Results
Asp.net core adding Controller using Entity Framework
Angular2 routing is not working on Production IIS
JWT - Configuring a Authorization Server and setting the issuer as itself
Web.config transform overwriting main web.config in TFS folder
create online .psd file render to html 5 css 3 and simple edit on it with asp.net c#
.net atomic operation with an external dll
asp.net webform System.ComponentModel.DataAnnotations Validate.TryValidateObject is not working
How to restrict access a folder in my domain using web.config file aspx page
How to call a another razor-template in razor-template in asp.net
Suddenly intranet sites need to be added to the I.E. Compatibility mode list. Why?
ASP.NET MVC 5 URL rewrite non-www to www http Post not working
Optimizing HTTP Web requests to lower the CPU/Memory/Port stress
How to persist a dropdown selected value used in Master page to all content pages in asp.net
web.config image to web page redirect in .Net?