简体   繁体   English

程序使用Microsoft Visual Studio文件夹而不是相对路径

[英]Program uses Microsoft Visual Studio folder instead of relative path

When I try to run .aspx page with next code: 当我尝试使用下一个代码运行.aspx页面时:

System.IO.File.Delete("~/img/afisha/" + fileName);

it writes a message: "Could not find a part of the path 'C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\~\\img\\afisha\\brs_01.jpg'." 它会写一条消息:“找不到路径'C:\\ Program Files \\ Microsoft Visual Studio 9.0 \\ Common7 \\ IDE \\〜\\ img \\ afisha \\ brs_01.jpg'的一部分。” But I need to use relative path. 但是我需要使用相对路径。

ps. PS。 the same thing happens with the connection string: <add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add> 连接字符串会发生相同的事情: <add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add> <add name="accessConStr" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; data source=ExpertBase.mdb; Persist Security Info=False;" providerName="System.Data.OleDb"></add>

Any ideas? 有任何想法吗? (and will it work on the server properlly?) (它将在服务器上正常运行吗?)

Try Server.MapPath() 试试Server.MapPath()

System.IO.File.Delete(Server.MapPath("~/img/afisha/" + fileName));

for the connection string you can try using a variable string instead 对于连接字符串,您可以尝试使用变量字符串代替

internal readonly string CONNECTION_STRING = "Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Persist Security Info=False;"

internal static string ConnectionString
{   
    get 
    { 
         return string.Format(CONNECTION_STRING, 
             Server.MapPath("~/ExpertBase.mdb")); 
    } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 文件夹文件路径 - Visual Studio Folder file path Visual Studio c#相对路径,即使找到正确的路径,程序也会搜索两个路径 - Visual Studio c# relative path, program searching two paths even when it finds the correct one Visual Studio使用UserControlDesigner而不是CustomDesigner - Visual Studio uses UserControlDesigner instead of CustomDesigner Visual Studio 中的相对文件路径问题 - Relative file path issue in Visual Studio 如何在 visual studio 中获取文件的相对路径? - How to get relative path of a file in visual studio? 在Visual Studio模板中更改项目文件夹路径 - Change Project Folder Path in Visual Studio Template Microsoft .NET Core 3 和 Visual Studio - 将源代码移动到新路径/文件夹/目录后,Linq 添加迁移无法创建应用程序 - Microsoft .NET Core 3 & Visual Studio - Linq Add Migration fails to createapphost after moving source code to new path / folder / directory Visual Studio发布使用调试模式而不是发布 - Visual Studio publish uses debug mode instead of release 是否可以在Visual Studio 2008中为具有相对路径的DLL设置共享文件夹? - Is it possible to setup a shared folder for DLLs with relative pathing in Visual Studio 2008? Visual Studio 2015发布版本使用错误的路径 - Visual Studio 2015 Release build uses wrong path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM