Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When iam executing iam getting the problem. the network path was not found
can any help was the problem is..thanks in advance
C#
public void ProcessRequest(HttpContext context)
        {
            string imagePath = context.Request.QueryString["image"];

            // split the string on periods and read the last element, this is to ensure we have
            // the right ContentType if the file is named something like "image1.jpg.png"
            string[] imageArray = imagePath.Split('.');

            if (imageArray.Length <= 1)
            {
                throw new HttpException(404, "Invalid photo name.");
            }
            else
            {
                FileStream file = new FileStream(imagePath,FileMode.Open);
                byte[] buffer = new byte[(int)file.Length];
                file.Read(buffer,0,(int)file.Length);
                file.Close();

                context.Response.ContentType = "application/octet-stream";

                ////context.Response.AddHeader("content-disposition","attachment
                context.Response.BinaryWrite(buffer);
                context.Response.End();
                //context.Response.Write(imagePath);
                //context.Response.ContentType = "image/" + imageArray[imageArray.Length - 1];
                //context.Response.WriteFile(imagePath);
            }
        }

        public bool IsReusable
        {
            get { return true; }
        }

    }
}
Posted
Updated 5-Oct-12 5:00am
v2
Comments
priyanka Dhoble 5-Oct-12 10:36am    
Where is the image file stored on client or server? And what is the value of imagePath?

1 solution

There is no problem with the code.

The problem is in tour image file name along with the path.
context.Request.QueryString["image"]

So, you check what the value is return from the querystring["image"]
and check whether you ca access it in file explorer.

I am sure, the path you passed in querystring is invalid. So, resolving this will make your program run with no issues.

cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900