Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am saving my files in the folder in my web form project /Upload/Secret/ and its saved correct. and i save the file name in SQL server database. I am try to view the files which is pdf and i created new item to my project .dbml and i drag and drop my table on that item. Now when i press the link button to view my file this error appeared : Could not find a part of the path.

I got this code from youtube https://www.youtube.com/watch?v=h7sswv6LyIw

protected void linkfilebtn_Click1(object sender, EventArgs e)
        {
            int Rowindex = ((GridViewRow)((sender as Control)).NamingContainer).RowIndex;
            string filelocation = DGDEPT.Rows[Rowindex].Cells[3].Text;
            string filepath = Server.MapPath("~/Upload/Secret/" + filelocation);

            WebClient user = new WebClient();
            Byte[] filebuffer = user.DownloadData(filepath);

            if (filebuffer != null)
            {
                Response.ContentType = ("application/pdf");
                Response.AddHeader("content-length", filebuffer.Length.ToString());
                Response.BinaryWrite(filebuffer);
            }
        }


What I have tried:

when i debug the code the string filelocation return null.when i use the physical path the file open and work but with virtual path show error
could not find a part of the path

the error appear in this line

Byte[] filebuffer = user.DownloadData(filepath);


how to solve this error and view my pdf file ?
Posted
Updated 19-Jan-19 10:32am
v2
Comments
Bryian Tan 19-Jan-19 16:33pm    
Quote:when i debug the code the string filelocation return null sound like you need to find out why filelocation is null and not physical vs absolute path issue.

1 solution

Quote:
when i debug the code the string filelocation return null.

So use the debugger and find out why.
It gets filled from a cell, so start there. Look at the row, look at the cell, check the Rowindex value. IT unlikely to be actually null, since Text properties don't normally return those, they return the empty string which is different.

We can't do any of that for you, we have no access to your code while it is running, or to you data. And you need both of those to work out what is going on.
 
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