3

I have 2 pages send.aspx and recive.aspx.

In send.aspx, I have FileUpload and Button that send selected file to recive.aspx page.

In below you can see recive.aspx.cs code in Page_Load at the end .

How can I send file to this page?

 protected void Page_Load(object sender, EventArgs e)
    {
        string action = Request.Params["action"];

        if (action == null)
        {
            Response.StatusCode = 400;
            Response.End();
        }


        if (action.Equals("upload"))
        {
            HttpPostedFile file = Request.Files["file"];
            if (file != null && file.ContentLength > 0)
            {
                //string guid = Guid.NewGuid().ToString();
                string ext = Path.GetExtension(file.FileName);
                //2- Get and check file extension
                string[] validExtesions = { ".e", ".jpg", ".gif", ".png", ".rar",
                ".zip",".3gp",".3gpp",".mp4",".mov",".wmv",".avi", "",".jpeg", ".mp3", ".ogg"};

                if (Array.IndexOf(validExtesions, ext.ToLower()) < 0)
                {
                    Response.Write("Invalid file extension!");
                    Response.End();
                }
                //3- Get and check file size
                long fileSize = file.ContentLength;
                fileSize /= 1024;
                if (fileSize > 2048000)
                {
                    Response.Write("Fiele size must be < 2GB");
                    Response.End();
                }
                //4- Get file name
                string fileName = Path.GetFileName(file.FileName);
                //5- Check file exist and if (true) generate new name
                while (File.Exists(Path.Combine(UploadFolder, fileName)))
                    fileName = "1" + fileName;
                string fname = fileName;
                string path = Server.MapPath(Path.Combine(UploadFolder, fname));


                file.SaveAs(path);

                Response.Write(fname);
                Response.End();
            }
            else
            {
                Response.StatusCode = 400;
                Response.End();
            }
        }


    }
Frost_Mourne
  • 342
  • 4
  • 22
behnamhaji
  • 151
  • 7
  • https://stackoverflow.com/questions/23751049/is-it-possible-to-send-file-from-one-web-page-to-another-in-asp-net see if this Question helps u – Frost_Mourne Jun 20 '17 at 07:37
  • https://stackoverflow.com/questions/34655932/how-to-send-files-to-another-web-page-using-web-client-with-asp-net-4-0 refer this one too – Frost_Mourne Jun 20 '17 at 08:33
  • Possible duplicate of [how to send files to another web page using web client with asp.net 4.0](https://stackoverflow.com/questions/34655932/how-to-send-files-to-another-web-page-using-web-client-with-asp-net-4-0) – VDWWD Jun 20 '17 at 10:00

0 Answers0