Question

I have two actions and I want to send HttpPostedFile from first action to another action using session or tempdata. who can help realize it this is my code, exeption in xdocument load - IIs Express/*.xml don't found

    [HttpPost]
    public ActionResult Index(HttpPostedFileBase fil)
    {

        if (fil != null && fil.ContentLength > 0)
        {


            Session["doc2"] = fil;

        }

        return RedirectToAction("Xmlview");
    }

    [HttpGet]
    public ActionResult Xmlview()
    {

        HttpPostedFileBase file2= Session["doc2"] as HttpPostedFileBase;

        var fileex = Path.GetExtension(file2.FileName);

        var fileName = Path.GetFullPath(file2.FileName);

        string xmlstr = ".xml";

        Value model2 = new Value();
        string strall = "";

        if (fileex.Contains(xmlstr))
        {
        XDocument xml = XDocument.Load(fileName);  // exeption hear IIs Express/*.xml don't found
        var allElements = xml.Elements();



    }
Was it helpful?

Solution

Try this. Hope it will work. I din't gave a try.

[HttpPost]
public ActionResult Index(HttpPostedFileBase fil)
{
    if (fil != null && fil.ContentLength > 0)
    {
        // Read bytes from http input stream
        BinaryReader b = new BinaryReader(file.InputStream);
        byte[] binData = b.ReadBytes(file.InputStream.Length);
        string result = System.Text.Encoding.UTF8.GetString(binData);
        Session["doc2"] = result;

    }
    return RedirectToAction("Xmlview");
}

[HttpGet]
public ActionResult Xmlview()
{
    Value model2 = new Value();
    string strall = "";
    string content = Session["doc2"].ToString();
    if (!String.IsNullOrEmpty(content))
    {
        XDocument xml = XDocument.Parse(content);  
        var allElements = xml.Elements();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top