Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I have encountered a problem when I want to call my file "zips.json" that exist inside of my Project. I want to call the file and upload it to my server !

please find the structure used:

byte[] responseArray = myWebClient.UploadFile("my server url", ".\\zips.json");
but the system appears an error that he can't retrieve the file knowing that I have added the file in the same level with the program.cs file of my C# project ?!!

please can you help me.

Best regards

Yassine
Posted
Comments
Sergey Alexandrovich Kryukov 30-Jul-13 11:57am    
What do you mean by "call a file"? File is not a function, method, procedure, subroutine, property or an operator...
—SA

OK, first there is no correlation between having it in the same directory as you *.cs files and it being available to your executable when it runs. The executable runs (assuming through the debugger or you haven't moved it) from the bin\debug or bin\release directories. Since you are looking for the file in the same folder as the executable, it can't find it because its a couple levels up in the source directory.

There's a couple ways you can fix this. If you'll only ever run it in the debugger or from the source folder, you can add some ..\\'s until you get to the right folder level, but at that point you are almost better off programming the entire absolute path to the file, etc: c:\\my dir\\zips.json

What you should do is this:

In the IDE, right click on your project and select "Add->Existing Item". Find your zips.json file and click to add it to your project. It will now show up in your project explorer. Click on the zips.json file once and go to the properties window. In the Build Action box make sure it says "None", and in the Copy To Output Directory box make sure it says "Copy Always".

This will make sure that the file in the *.cs directory always gets copied to the program output directory and is available for you to use. If you update the file you only have to update it in one place and it will automatically copy the next time you build or run.
 
Share this answer
 
Maybe you don't understand what upload does? Your "my server URL" cannot be "just URL", it should be a server-side script capable of handling post data with uploads. Did you implement it?
See, for example, this CodeProject article: File Upload with ASP.NET[^].

—SA
 
Share this answer
 
Hi thanks for your response I already found a solution to solve it it's like yours best regards
Yassine
 
Share this answer
 

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



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