Q:

How to save file to server without using html fileupload control?

I am using Reportviewer in asp.net mvc and rendering it as a pdf format after converting it into byte. 
The code is given below:
    public ActionResult PrintPO(string type)
    {
        LocalReport lr = new LocalReport();
        string path = Url.Content(Server.MapPath("~/Report/RepPurchaseOrder.rdlc"));
        if (System.IO.File.Exists(path))
        {
            lr.ReportPath = path;
        }
        else
        {
            return Content("Report File Not Found!");
        }

        ReportDataSource rd = new ReportDataSource("Data", list));

        lr.DataSources.Add(rd);

        string reportType = type;
        string mimeType;
        string encoding;
        string fileNameExtension;

        string deviceInfo =

        "<DeviceInfo>" +
        "  <OutputFormat>" + id + "</OutputFormat>" +
        "  <PageWidth>10in</PageWidth>" +
        "  <PageHeight>10in</PageHeight>" +
        "  <MarginTop>0.5in</MarginTop>" +
        "  <MarginLeft>1in</MarginLeft>" +
        "  <MarginRight>1in</MarginRight>" +
        "  <MarginBottom>0.5in</MarginBottom>" +
        "</DeviceInfo>";

        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;

        renderedBytes = lr.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

        FileContentResult fileResult = File(renderedBytes, mimeType);

        return fileResult;
    }

I want to save this file to my server location. For example: /Content/PDF/Result1.pdf
I want to make a copy of rendered bytes into file so that I can see preview of it later also.
How can I achieve it? I am not using html FileUpload control.
Please help me.
Thanks.

A:

You can save it using FileStream in server-side. 
using (FileStream fileStream = System.IO.File.Create(filePath, renderedBytes.Length)){
    fileStream.Write(renderedBytes, 0, renderedBytes.Length);
}

I've added the code to save file in specified file path(/Content/PDF/Result1.pdf) at the end of the method before setting FileContentResult
public ActionResult PrintPO(string type)
{
    LocalReport lr = new LocalReport();
    string path = Url.Content(Server.MapPath("~/Report/RepPurchaseOrder.rdlc"));
    if (System.IO.File.Exists(path))
    {
        lr.ReportPath = path;
    }
    else
    {
        return Content("Report File Not Found!");
    }

    ReportDataSource rd = new ReportDataSource("Data", list));

    lr.DataSources.Add(rd);

    string reportType = type;
    string mimeType;
    string encoding;
    string fileNameExtension;
    string id="Dynamic ID Will Be Here";

    string deviceInfo =
    "<DeviceInfo>" +
    "  <OutputFormat>" + id + "</OutputFormat>" +
    "  <PageWidth>10in</PageWidth>" +
    "  <PageHeight>10in</PageHeight>" +
    "  <MarginTop>0.5in</MarginTop>" +
    "  <MarginLeft>1in</MarginLeft>" +
    "  <MarginRight>1in</MarginRight>" +
    "  <MarginBottom>0.5in</MarginBottom>" +
    "</DeviceInfo>";

    Warning[] warnings;
    string[] streams;
    byte[] renderedBytes;

    renderedBytes = lr.Render(
        reportType,
        deviceInfo,
        out mimeType,
        out encoding,
        out fileNameExtension,
        out streams,
        out warnings);

    //Saving renderedBytes to File ~/Content/PDF/Result1.pdf
    var filesDir = Server.MapPath(@"~/Content/PDF");
    if (!Directory.Exists(filesDir)) {
        Directory.CreateDirectory(filesDir);
    }
    var filePath = Path.Combine(filesDir, "Result1.pdf");
    using (FileStream fileStream = System.IO.File.Create(filePath, renderedBytes.Length)) {
        fileStream.Write(renderedBytes, 0, renderedBytes.Length);
    }

    FileContentResult fileResult = File(renderedBytes, mimeType);

    return fileResult;
}

