English 中文(简体)
a. 接近URL[复制]的绝对档案途径
原标题:Absolute file path to relative URL [duplicate]

我看到许多辅导员在解决相对权宜到绝对道路上,但我想做的是相反的:将一个系统绝对卷宗排入相对权。

Is there a nice hack-free way to turn a filepath like c:my_website_rootimagespicture_a.jpg into images/picture_a.jpg

我曾看过<代码>Uri.MakeRelative(),但我想,在这种情况下会使用。

Edit:我已经照此执行,似乎仍然很 ha(第2行)。

var urlPath = new Uri(@"c:mywebfolderimagespicture1.jpg");
var urlRoot = new Uri(Server.MapPath("~")+"/");
string relative = urlRoot.MakeRelativeUri(urlPath).ToString();
问题回答

在IIS,建立了虚拟名录images,并将其贴在c:my_website_rootimages

如果贵国网站已经指示c:my_website_root,那么你就不需要做任何事情。

如果你需要把所有相对的尿素转换为绝对的尿素,则使用这一缩略语:

Private Function ConvertALLrelativeLinksToAbsoluteUri(ByVal html As String, ByVal PageURL As String)
    Dim result As String = Nothing

      Getting all Href
    Dim opt As New RegexOptions

    Dim XpHref As New Regex("(href="".*?"")", RegexOptions.IgnoreCase)

    Dim i As Integer
    Dim NewSTR As String = html
    For i = 0 To XpHref.Matches(html).Count - 1
        Application.DoEvents()
        Dim Oldurl As String = Nothing
        Dim OldHREF As String = Nothing
        Dim MainURL As New Uri(PageURL)
        OldHREF = XpHref.Matches(html).Item(i).Value
        Oldurl = OldHREF.Replace("href=", "").Replace("HREF=", "").Replace("""", "")
        Dim NEWURL As New Uri(MainURL, Oldurl)
        Dim NewHREF As String = "href=""" & NEWURL.AbsoluteUri & """"
        NewSTR = NewSTR.Replace(OldHREF, NewHREF)


    Next

    html = NewSTR

    Dim XpSRC As New Regex("(src="".*?"")", RegexOptions.IgnoreCase)

    For i = 0 To XpSRC.Matches(html).Count - 1
        Application.DoEvents()
        Dim Oldurl As String = Nothing
        Dim OldHREF As String = Nothing
        Dim MainURL As New Uri(PageURL)
        OldHREF = XpSRC.Matches(html).Item(i).Value
        Oldurl = OldHREF.Replace("src=", "").Replace("src=", "").Replace("""", "")
        Dim NEWURL As New Uri(MainURL, Oldurl)
        Dim NewHREF As String = "src=""" & NEWURL.AbsoluteUri & """"
        NewSTR = NewSTR.Replace(OldHREF, NewHREF)


    Next


    Return NewSTR


End Function




相关问题
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. ...

热门标签