Sql server 2008 asp.net MVC将数据库中的相对路径保存为非完整路径
asp.net MVC将数据库中的相对路径另存为Sql server 2008 asp.net MVC将数据库中的相对路径保存为非完整路径,sql-server-2008,asp.net-mvc-4,entity-framework-5,uploadify,Sql Server 2008,Asp.net Mvc 4,Entity Framework 5,Uploadify,asp.net MVC将数据库中的相对路径另存为 ~/Content/Uploads/11thMay.jpg 不是完整的路径 D:/Projects/HRMV2/CubicHRMWeb/Content/Uploads/11thMay.jpg 我想保存相对路径,但正在保存数据库中的完整路径 我怎么做? 谢谢。如果您的问题是“如何保存为完整路径”,请尝试此选项 string path = Path.Combine(Server.MapPath("~/Content/img/Company/Log
~/Content/Uploads/11thMay.jpg
不是完整的路径
D:/Projects/HRMV2/CubicHRMWeb/Content/Uploads/11thMay.jpg
我想保存相对路径,但正在保存数据库中的完整路径
我怎么做?
谢谢。如果您的问题是“如何保存为完整路径”,请尝试此选项
string path = Path.Combine(Server.MapPath("~/Content/img/Company/LogoFiles"), filename);
[HttpPost]
public ActionResult Save(HttpPostedFileBase myFile)
{
string filename = myFile.FileName;
string relativeFileName = "~/Content/Uploads/" + filename;// relative path
return View();
}
如果您的问题是“如何保存为相对路径”,请尝试此选项
string path = Path.Combine(Server.MapPath("~/Content/img/Company/LogoFiles"), filename);
[HttpPost]
public ActionResult Save(HttpPostedFileBase myFile)
{
string filename = myFile.FileName;
string relativeFileName = "~/Content/Uploads/" + filename;// relative path
return View();
}
如果您的问题是“如何保存为完整路径”,请尝试此选项
string path = Path.Combine(Server.MapPath("~/Content/img/Company/LogoFiles"), filename);
[HttpPost]
public ActionResult Save(HttpPostedFileBase myFile)
{
string filename = myFile.FileName;
string relativeFileName = "~/Content/Uploads/" + filename;// relative path
return View();
}
如果您的问题是“如何保存为相对路径”,请尝试此选项
string path = Path.Combine(Server.MapPath("~/Content/img/Company/LogoFiles"), filename);
[HttpPost]
public ActionResult Save(HttpPostedFileBase myFile)
{
string filename = myFile.FileName;
string relativeFileName = "~/Content/Uploads/" + filename;// relative path
return View();
}
这段代码不允许保存相对路径,当您尝试它时,会设置文件名的总数,而不仅仅是文件名。如果您在这一点上插入断点,您必须获得如下结果
"/content/Uploads/C:Document/Picture/father.jpeg"
而不是你想要的相对路径
"/content/Uploads/father.jpeg"
这段代码不允许保存相对路径,当您尝试它时,会设置文件名的总数,而不仅仅是文件名。如果您在这一点上插入断点,您必须获得如下结果
"/content/Uploads/C:Document/Picture/father.jpeg"
而不是你想要的相对路径
"/content/Uploads/father.jpeg"
为了保存文档的相对路径,应该使用system.io的getfilename属性,如下例所示 我假设您希望在控制器的post方法中执行此操作,该方法包含一个模型或httppostedfilebase 在我的示例中,我有一个名为imagefichier的具有httppostedfilebase属性的模型,因此您可以通过执行此操作来获取文档名
var lefilename = System.IO.Path.GetFileName(model.imagefichier.FileName);
//Suppose that you want to save it in your root web file
//like ~/Images/Administrateur/leilename,you can do it like this
string cheminbdd = "~/Images/Administrateur/" + lefilename;
//it is cheminbdd that you can save in your database as your relative path
为了保存文档的相对路径,应该使用system.io的getfilename属性,如下例所示 我假设您希望在控制器的post方法中执行此操作,该方法包含一个模型或httppostedfilebase 在我的示例中,我有一个名为imagefichier的具有httppostedfilebase属性的模型,因此您可以通过执行此操作来获取文档名
var lefilename = System.IO.Path.GetFileName(model.imagefichier.FileName);
//Suppose that you want to save it in your root web file
//like ~/Images/Administrateur/leilename,you can do it like this
string cheminbdd = "~/Images/Administrateur/" + lefilename;
//it is cheminbdd that you can save in your database as your relative path
否我想保存相对路径,但在DB中保存了完整路径否我想保存相对路径,但在DB中保存了完整路径