0
我将图像上传到文件夹并将其路径保存到db.Here是我的代码。将图像路径存储为asp.net中的单个正斜杠
[HttpPost]
public ActionResult UploadPic(FileManagement fmanage, HttpPostedFileBase file)
{
string email = User.Identity.Name;
if (file != null && file.ContentLength > 0)
{
var FileName = string.Format("{0}.{1}", Guid.NewGuid(), Path.GetFileName(file.FileName));
var path = Path.Combine(Server.MapPath("~/Content/Uploads"), FileName);
file.SaveAs(path);
using (var session = DocumentStore.OpenSession("RavenMemberShip"))
{
var query = from q in Session.Query<Registration>() where q.Email == email select q;
if (query.Count() > 0)
{
foreach (var updated in query)
{
updated.FileName = FileName;
updated.Path = path;
session.SaveChanges();
}
}
}
}
else
ModelState.AddModelError("", "Remove the errors and try again");
return View();
}
但路径存储为双斜杠,这是wrong.How我可以保存路径为单个斜线。 在此先感谢您的帮助。
明白了我的意思,修改我的源代码,现在它按预期工作。谢谢! – Wasfa