Reputation: 27
I have some problem with my open new window popup which it can read my path and it like throw away my "/" sign in it. So it will be see like this "C:UsersKHAIRADesktopheitechHibah Total v1.2/Secure/PDF Folder"
Can anyone help me to make it look/read like this "C:Users/KHAIRA/Desktop/heitech/Hibah Total v1.2/Secure/PDF Folder".
I have open button in gridview that will open new window and view the pdf file here the coding from ViewDocument.aspx
string commandName = e.CommandName.ToString().Trim();
GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
string folderName = ConfigurationManager.AppSettings["folderPDF"].ToString();
string path = Server.MapPath("~") + "/Secure/";
string fullPath = path + folderName;
string[] filePaths = Directory.GetFiles(fullPath, "*.pdf");
switch (commandName)
{
case "Open":
string script = "<script language=\"JavaScript\">\n";
script += "window.open ('OpenForm.aspx?path=" + row.Cells[0].Text;
script += "','CustomPopUp', config='height=500,width=1024, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no')\n";
script += "</script>";
this.ClientScript.RegisterStartupScript(this.GetType(), "onload", script);
break;
for the OpenForm.aspx.cs coding :
catch(Exception ex)
{
try
{
string paths = Request.QueryString["path"].ToString();
bool fileExist = File.Exists(paths);
if (fileExist)
{
Response.ContentType = "Application/pdf";
Response.TransmitFile(paths);
}
else
{
Label1.Text = "File Not Exist";
}
}
However, i realize that the problem is from here
string paths = Request.QueryString["path"].ToString();
Upvotes: 1
Views: 980
Reputation: 48600
First things first.
The local system path separator is \
e.g. C:\Windows
.
/
is for web e.g. http://stackoverflow.com/questions/9902129/how-to-make-the-path-have/9902194#9902194
For a single \
you have to put \\
(remember escape sequence)
Or
Use String Verbatim
string path = @"C:\Users\KHAIRA\Desktop\heitech\Hibah Total v1.2\Secure\PDF Folder"
Or
Use Path.Combine method of System.IO namespace like
Path.Combine("C:", "Users");
It will give return a string
C:\Users
Upvotes: 2
Reputation: 898
Try this
String path=@"C:Users/KHAIRA/Desktop/heitech/Hibah Total v1.2/Secure"
String fullpath=path + "\\\" + "PDF Folder"
Fullpath will contain the path you want
Upvotes: 0
Reputation: 3529
Try to use something like this:
string path = "C:Users\\KHAIRA\\Desktop\\heitech\\Hibah Total v1.2\\Secure\\PDF Folder";
Upvotes: 0