Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
When iam executing iam getting the problem. the network path was not found
can any help was the problem is..thanks in advance
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 5-Oct-12 4:22am
Edited 5-Oct-12 5:00am
v2
Comments
priyanka Dhoble at 5-Oct-12 10:36am
   
Where is the image file stored on client or server? And what is the value of imagePath?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 468
1 Sergey Alexandrovich Kryukov 305
2 PhilLenoir 115
3 RajeeshMenoth 110
4 Peter Leow 100
0 Sergey Alexandrovich Kryukov 6,557
1 OriginalGriff 5,966
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,540


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100