question

dark-3963 avatar image
0 Votes"
dark-3963 asked Viorel-1 edited

c# WebClient cant access a forbidden File

 string pcIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
 WebClient webClient = new WebClient();
 File.Delete(@"C:\Users\Mustafa\Pictures\Camera Roll\deneme.png");
             webClient.DownloadFile("http://pcIP/C:/Users/Public/Pictures/ipDeneme/1.png", "C:/Users/Mustafa/Pictures/Camera Roll/deneme.png");
    
 pictureBox1.ImageLocation = @"C:\Users\Mustafa\Pictures\CameraRoll\deneme.png";


I run this code but I get the file is forbidden error how can I solve this?

dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you use Server.MapPath Method in your web application, then you will have access to folders of the web server.
But even so, the url cannot be written like it is now, please check this post:
Server.MapPath(“.”), Server.MapPath(“~”), Server.MapPath(@“\”), Server.MapPath(“/”). What is the difference?

0 Votes 0 ·
vb2ae avatar image
1 Vote"
vb2ae answered

this is not a valid url for the image

http://pcIP/C:/Users/Public/Pictures/ipDeneme/1.png

you need to put the image in a folder that is hosted under the website using the pcIP

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Maybe consider a different approach:

 pictureBox1.Image = null;
 File.Copy( @"C:\Users\Public\Pictures\ipDeneme\1.png", @"C:\Users\Mustafa\Pictures\Camera Roll\deneme.png", true );
 pictureBox1.ImageLocation = @"C:\Users\Mustafa\Pictures\Camera Roll\deneme.png";


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.