2012-03-28 95 views
1

我打开新窗口弹出窗口时会出现一些问题,它可以读取我的路径并像扔掉我的“/”符号。所以它会看到这样的“C:UsersKHAIRADesktopheitechHibah Total v1.2 /安全/ PDF文件夹”如何使路径具有“/”

任何人都可以帮助我看起来/这样读“C:Users/KHAIRA/Desktop/heitech/Hibah Total v1.2 /安全/ PDF文件夹“。

我在GridView的打开按钮,将打开新窗口,查看这里的PDF文件从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; 

编码为OpenForm.aspx.cs编码:

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"; 
     } 
    } 

但是,我意识到问题是从这里开始的

string paths = Request.QueryString["path"].ToString(); 
+5

帮助你,你需要显示一些源代码... – Yahia 2012-03-28 06:21:23

+0

你可以发布你使用的代码,你输入什么,以及它失败的地方。 – 2012-03-28 06:22:35

回答

2

第一件事是第一件事。

本地系统路径分隔符是\例如, C:\Windows

/适用于网页例如http://stackoverflow.com/questions/9902129/how-to-make-the-path-have/9902194#9902194

对于你有一个\\\(记住转义序列)

或者

使用字符串逐字

string path = @"C:\Users\KHAIRA\Desktop\heitech\Hibah Total v1.2\Secure\PDF Folder" 

或者

使用路径。结合System.IO命名空间的方法类似

Path.Combine("C:", "Users"); 

它会给返回一个字符串

C:\Users 
+0

这是一个疯狂的猜测。 – PraveenVenu 2012-03-28 06:31:34

0

尝试使用这样的:

string path = "C:Users\\KHAIRA\\Desktop\\heitech\\Hibah Total v1.2\\Secure\\PDF Folder"; 
+0

这只会在我的笔记本电脑上工作。一旦我尝试在其他笔记本电脑或PC上运行它,它将无法工作。 – Kairash 2012-03-28 06:34:44

+0

可能是因为在其他笔记本电脑或PC上没有名为KHAIRA的用户,或者该路径的其他部分不存在? – 2012-03-28 06:41:04

+0

是的,这就是为什么我使用Sever.MapPath(“〜”)使它更灵活,但它可以工作,当我尝试打开新窗口。它似乎不能读取它。 – Kairash 2012-03-28 06:56:52

0

试试这个

String [email protected]"C:Users/KHAIRA/Desktop/heitech/Hibah Total v1.2/Secure" 

String fullpath=path + "\\\" + "PDF Folder" 

Fullpath将包含所需的路径