English 中文(简体)
如何在 ASP. NET MVC 中指定文件路径
原标题:How to specify a file path in ASP.NET MVC

我想指定文件的虚拟路径, 但我无法这样做 。

这是我的代码:

int Course_Id = 1;
int PortfolioID=1;
int ChandidateID=1;

string filepath = Server.MapPath("~/ePortfolio/PortFolioContent/" + Course_Id + "/Assignments/Exhb_" + item.PortfolioID + "_" + item.ChandidateID + ".jpg");

if(System.IO.File.Exists((filepath)))
{                            
    ViewBag.Thumbnail = filepath;
}

When i use Server.MapPath it is fetching data from some other path:
My original path is:
E:HOBBYHOMES(E-PORTFOLIO)HobbyHomesWebAppePortfolioPortFolioContent1Assignments
but it is taking this path
E:HOBBYHOMES(E-PORTFOLIO)HobbyHomesWebAppActivityPostinImagesePortfolioPortFolioContent1AssignmentsExhb_1_1.jpg
I m not understanding why this is workin so.Please help me

最佳回答

尝试 stringing filepath = Server. MapPath ("~/..."jpg");

问题回答

您可以使用 @ell. Content ("~/ Content/ Imaages/ yourImaageName. png") 。

尝试做这样的事情:

Path.Combine(Server.MapPath("~/"),("ePortfolio\PortFolioContent\" + Course_Id + "\Assignments\Exhb_" + item.PortfolioID + "_" + item.ChandidateID + ".jpg"));

从理论上讲,它导致的答案与你之前的答案相同。 实际上,它可能会产生完全不同的答案。

此处还有一个最近的问题( 目前我找不到这个问题), 它突出显示服务器. MapPath ("~/.etc.") 有时在重写请求路径上的行为不端 。 您正在重写想要形成此路径的请求吗?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签