Click here to Skip to main content
15,393,377 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have published my application on my server. All faculties are using it on line. The application have one user called admin. Admin daily upload a file (.csv) through a file upload control. The data in the file is shown below in grid view after uploading. The file should be present on user computer in c: drive. But the error is showing invalid path. The problem is that it taking the servers path. It is searching the file on servers C: drive. How to overcome this problem.
Posted
Comments
CRDave1988 14-Feb-12 1:45am
   
i u want to show file after upload than why u want it from client u can show that from server.
Qureshali 14-Feb-12 1:48am
   
the user generates that file on client computer from bio matrix in csv format and then upload it on server. So how is this possible
CRDave1988 14-Feb-12 2:07am
   
where this file u store on server?
Qureshali 14-Feb-12 2:54am
   
File is not stored on server. Sir, actually the file should be present on clients c: drive. But i think its searching the file on servers c: drive. How to over come this problem
Michael dg 14-Feb-12 2:58am
   
Qureshali, you should save the uploaded csv on the server system directory.
Qureshali 14-Feb-12 3:11am
   
How to do that sir. Can you elaborate please
Michael dg 14-Feb-12 2:57am
   
I think you upload the file on the server but you did not save/store it on the database or in the server system directory.
Varun Sareen 14-Feb-12 2:57am
   
If once the admin is uploading the file on the server then why it required by the clients and why the file need to be present on the client computer as the file can easily be read from the server and the data is being shown in the grid to the users.
CRDave1988 14-Feb-12 2:59am
   
u r saying that "upload it on server" and also saying that "File is not stored on server." this is contradict. like wood is burning and it is cold also.
Varun Sareen 14-Feb-12 3:01am
   
absolutely right Dave. The question to me also seems very confusing...what he is trying to achieve?
CRDave1988 14-Feb-12 3:00am
   
I m agree with Varun Sareen
Varun Sareen 14-Feb-12 3:01am
   
thanks
Al Moje 16-Feb-12 20:47pm
   
Please see additional notes on my answer below pertaining to my article..

You can't access the users HDD - he has to browse to the file with an upload control, and press a button - then the file (but not any information as to where it came from, security won't allow that) can be uploaded.

Alternatively, you could write software which runs as a service on his PC and uploads it automatically.

But the server cannot "reach out" into the users PC and just grab the file. There is a lot of software out there specifically to prevent that!
   
First of all your logic for getting data from your csv file is wrong.
you need not use the user computer for reading that uploaded csv file.

what you need to do is,

1) first select and upload that csv file to your server

2) read the data from that uploaded file and display it to your grid.
like if you upload that file to your temp directory held on server
then use server.mappath("~temp/first.csv"); that working fine..


reading file from user computer is the bad idea. because if i am the user of your application and i have no c:\ in my PC instead c:\ i use D:\ for my windows to install, then your system not work in my PC.. that's why reading file data from user PC is wrong idea. so always upload and save that file and use that file from server's directory.

and if you don't want to store that file on server because of security reasons then you can delete that file using system.io.file class after you read data from that file..

that's the better way.
   
heloo...Qureshali514


If you are uploading any Files like csv, or Images into IIS server You have to give full control for the uploaded folder... Then only you will be able to acces that file from the server...

right click the folder where you are uploading in IIS and In properties>Securities give full Permissions for IIS users then you will be able to access this file from clients....
   
Comments
sawzinmoe 28-Nov-17 3:12am
   
Thanks it is work for my issue.
Hi,

I thing you must have to create a sub folder in your project solution
to copy first the file to upload then open it rather than directly opening such file at local users computer that is why you are encountering such an error maybe cause by some restricted security access rights permission that was set by the Network administrator... After all you may have an option to delete such uploaded file after using it in your sub directory dump folder...

See my article if could help...
SQL
Upload Excel Spreadsheet File to Server, then Display Record(s) in Gridview



VB
xlsUpload.SaveAs(Server.MapPath("~/XlsUploadFile/" +
                        xlsUpload.FileName.ToString()));


Note:

The 'XlsUploadFile' folder should be existing in your project solution.
This sub directory is for dumping of uploaded file for saving, and also be sure that the
excel file headers matches the gridview DataField...

Please see my comments from the vote of 1 by: Captain Scarlet on my article...
Please remember to vote if could help...
   
v5

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