jao
jao

Reputation: 18610

string replace vb.net not working

What am I doing wrong here?

If FilePath.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: original string

This is what it looks like after my VB code: replaced string

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

Upvotes: 1

Views: 2225

Answers (1)

jao
jao

Reputation: 18610

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 %>)

Upvotes: 1

Related Questions