0

i am trying to save a file from chrome using AjaxSubmit. i got the problem that Chrome send the file in octet format and i am unable to check that if it is really image or anything else.

when i try to call

HttpPostedFileBase file

file.InputStream

inputstream caused error in chrome that Parameter is not valid.

how i can save them in asp.net c#

1 Answer 1

1

I use this in my view: <input type="file" id="deploymentPackage" name="deploymentPackage" />

And in my controller, I do this:

public ActionResult AddRelease(ApplicationReleaseViewModel appRelease, HttpPostedFileBase deploymentPackage)
        {
            if (ModelState.IsValid)
            {
                ApplicationRelease dto = new ApplicationRelease();
                appRelease.UpdateDto(dto);

                using (StreamReader sr = new StreamReader(deploymentPackage.InputStream))
                {
                    dto.DeploymentPackage = new byte[deploymentPackage.InputStream.Length];
                    deploymentPackage.InputStream.Read(dto.DeploymentPackage, 0, dto.DeploymentPackage.Length);
                }

                this.ApplicationService.AddApplicationRelease(dto);

                return RedirectToAction("Index", new { ActionPerformed = "ApplicationReleaseAdded", Name = appRelease.Name.CutToMaxLength(50).UrlEncode() });
            }
            else
            {
                ViewBag.PostAction = "AddRelease";

                return View("EditRelease", appRelease);
            }
        }

UPDATE: Look at this link, if you can't abstract yourself from "my" code.

http://www.codeproject.com/KB/aspnet/Implementing_HTTP_File_Up.aspx

Sign up to request clarification or add additional context in comments.

3 Comments

what is ApplicationReleaseViewModel i see this first time. anything special
Yes, that is my own view model for that specific View/Action. Don't pay attention to that.
Use the link I just added instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.