httppostedfilebase

Full path of the file from the remote server

倾然丶 夕夏残阳落幕 提交于 2020-03-05 08:03:34
问题 I am working with files and I don't really understand how to make it work. I have a web application (c#) that is located on the server and users use this application to upload some information from the files. The problem that I am having that users upload the file (using HttpPostedFileBase class) from their local machines but code is trying to match the same path on the server and of course the file doesn't exist on the server, that's why it throws an error saying that Cannot find a part of

Full path of the file from the remote server

核能气质少年 提交于 2020-03-05 08:01:23
问题 I am working with files and I don't really understand how to make it work. I have a web application (c#) that is located on the server and users use this application to upload some information from the files. The problem that I am having that users upload the file (using HttpPostedFileBase class) from their local machines but code is trying to match the same path on the server and of course the file doesn't exist on the server, that's why it throws an error saying that Cannot find a part of

MVC3 How to check if HttpPostedFileBase is an image

梦想与她 提交于 2019-12-31 08:46:27
问题 I have a controller like this: public ActionResult Upload (int id, HttpPostedFileBase uploadFile) { .... } How can I make sure that uploadFile is an image (jpg, png etc.) I have tried with using (var bitmapImage = new Bitmap (uploadFile.InputStream)) {..} which throws an ArgumentException if bitmapImage can not be created. Is there a better way for example by looking at uploadFile.FileName? 回答1: You can check the HttpPostedFileBase object's properties for this ContentType FileName (check the

MVC - Don't save null image data if image was not re-uploaded in HTTP post (from SportsStore example)

血红的双手。 提交于 2019-12-22 18:24:48
问题 I have been following the SportsStore example project in Apress Pro ASP.NET MVC 3 Framework book and trying to apply the concepts to my application. One area that is bugging me is that in the sample, I can add an image to a product and it gets saved to the database, but if I edit any given product, without uploading a new image for it, the image data is cleared out. I want to be able to edit a product, but if the image data returned from the HTTP post is null, that I want Entity Framework to

Save and delete Excel file saved using HttpPostedFileBase

被刻印的时光 ゝ 提交于 2019-12-22 09:49:13
问题 I am uploading an Excel file and extracting data from that and saving it into a database. I am using MVC4 .NET Framework. This is my code from class: public static void Upload(HttpPostedFileBase File) { NIKEntities1 obj = new NIKEntities1(); MyApp = new Excel.Application(); MyApp.Visible = false; string extension = System.IO.Path.GetExtension(File.FileName); string pic = "Excel" + extension; string path = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Excel"), pic);

Upload Image MVC always null

社会主义新天地 提交于 2019-12-20 05:47:05
问题 Hi everyone i am trying to upload a simple image but the HttpPostedFileBase is always remaining null. This is my code i dont know what i am doing wrong. This is my code in the design view: <fieldset> <legend>PictureModel</legend> <div class="editor-label"> <%: Html.LabelFor(model => model.PrivacyTypeID) %> </div> <div class="editor-field"> <%: Html.DropDownList("PrivacyTypeID", null, new { name = "PrivacyTypeID", title = "Please select privacy type.", id = "PrivacyTypeID" }) %> <%: Html

How do you convert a HttpPostedFileBase to an Image?

匆匆过客 提交于 2019-12-17 17:26:28
问题 I am using ASP.NET MVC and I've an action that uploads the file. The file is being uploaded properly. But I want width and height of the image. I think I need to convert the HttpPostedFileBase to Image first and then proceed. How do I do that? And please let me know if there is another better way to get the width and height of the image. 回答1: I use Image.FromStream to as follows: Image.FromStream(httpPostedFileBase.InputStream, true, true) Note that the returned Image is IDisposable . You'll

ASP.NET MVC passing Model *together* with files back to controller

冷暖自知 提交于 2019-12-12 17:18:34
问题 Ok, I've been going at this for several hours and I simply cannot find the solution. I want to get some data from my user. So first, I use a controller to create a view which receives a Model: public ViewResult CreateArticle() { Article newArticle = new Article(); ImagesUploadModel dataFromUser = new ImagesUploadModel(newArticle); return View(dataFromUser); } Then, I have the view: <asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server"> <h2>AddArticle</h2> <%

File Upload: Fail to assign value into File, keep poping null to me? Need help, any pro?

▼魔方 西西 提交于 2019-12-11 20:00:42
问题 I'm doing an upload in asp mvc, it is working great at first user attemp to attach a file into model, file is system.web.httpfilewrapper . But when it comes to second attemp where controller catching an invalid amount from other textbox, and it postback to the user saying invalid, thereafter the user type in a valid amount, and it goes back to the controller, here here then started making me have no idea what happened, file got suddenly went into null and it cant finish the following line of

MVC3/EF4.1 Binding HttpPostedFileBase to model and adding to DB

爷,独闯天下 提交于 2019-12-11 18:22:18
问题 I have an ActionResult which binds data to the model and adds it the the DB. Now what I want, is to have a file uploader, and the ActionResult to store the files and adding their FileName to the DB (so I can show the files/images at a later point). What is the best approach? Here is what I got so far (It can store the files, but im not sure how intelligent EF is, and how complex the datatypes can be): The model class: public class Annonce { public int Id { get; set; } public string Company {