如何将图像名称和文件夹保存到数据库中,在ASP.NET MVC中提供物理路径,即www.xyz.com [英] How to save image name and folder into database giving physical path i.e www.xyz.com in ASP.NET MVC

查看:93
本文介绍了如何将图像名称和文件夹保存到数据库中,在ASP.NET MVC中提供物理路径,即www.xyz.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将图像名称和图像foldername保存到数据库中,提供物理路径,即asp.net中的www.xyz.com mvc



但我得到的错误如下: SaveAs方法被配置为需要一个root路径,并且路径没有root。



如果它是相同的服务器url然后它工作正常没有问题,但我想要将图像文件保存到另一个服务器URL和该图像文件夹中。



我尝试过:



How to save image name and image foldername into database giving physical path i.e www.xyz.com in asp.net mvc

But i am getting error like: The SaveAs method is configured to require a rooted path, and the path is not rooted.

If it is same server url then it works fine no issue,but i want to save image file to another server url and in that image folder.

What I have tried:

 [HttpPost]
        public ActionResult streetstyle(FormCollection frm, HttpPostedFileBase Upload)
        {
string ImageName = System.IO.Path.GetFileName(Upload.FileName);
            string physicalPath = "http://www.xyz.com/" + "/ImagesFolder/" + ImageName;
            Upload.SaveAs(physicalPath);

            db.Name = frm["Name"];
            db.Email = frm["Email"];
            db.Mobile = frm["Mobile"];

            db.Image = ImageName;

推荐答案

花点时间思考一下发生了什么。此代码正在您的服务器上运行。而SaveAs需要一个文件夹的物理路径。所以,做这样的事情:

Take a moment and think about what is happening. This code is running on your server. And SaveAs needs a physical path to a folder. So, instead do something like this:
String physicalPath = Server.MapPath("~/ImagesFolder/"); // this will resolve to c:\inetpub\wwwroot\app1\imagesFolder or wherever the actual drive is.



然后将ImageName存储到数据库中。


Then just store ImageName into the db.


这篇关于如何将图像名称和文件夹保存到数据库中,在ASP.NET MVC中提供物理路径,即www.xyz.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆