string replace vb.net not working
What am I doing wrong here?
If FilePa开发者_如何学JAVAth.ToLower().Contains(".pdf") Then
Dim Replaced As String = FilePath.Replace("\","/")
FilePath = "http:" & Replaced
End If
If FilePath is for example \\sharepoint\file.pdf
, the expected output should be http://sharepoint/file.pdf
. However, the actual output is http:\\sharepoint\file.pdf
Update 1
This is the original string:
This is what it looks like after my VB code:
As you can see, the http: part is added, however the backslashes haven't been touched.
Update 2 It has something to do with the slashes. Because when I replace other characters (for example a with @), then the replaced string is shown correctly. But not the slashes
I still don't exactly understand why, but the following has fixed my code:
Dim Replaced As String = FilePath
If FilePath.ToLower().Contains(".pdf") Then
Replaced = FilePath.Replace("\","/")
Replaced = "http:" & Replaced
End If
and then in the vbscript code I use
Sub toonDocument()
dim spobject
set spobject = CreateObject("Sharepoint.Document")
spobject.FilePath = "<% = Replaced %>"
spobject.openen()
set spobject = nothing
so <% = Replaced %>
(instead of <%= FilePath %>
)
精彩评论