1

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

13
  • Are you sure FilePath contains: \\sharepoint\file.pdf at the start? How are you testing the input / output values? Commented May 26, 2011 at 8:26
  • 1
    I tried your code and unable to replicate. Please check: imgur.com/09Iwq Did you define FilePath as described? Commented May 26, 2011 at 8:28
  • Related to Regular Expressions ~ convert UNC to URL Commented May 26, 2011 at 8:39
  • @forsvarir, @Alex, see updated question. I added pictures so you can see that it does change something Commented May 26, 2011 at 8:45
  • 1
    @jao Both this code and the code in the related question definitely work. Your error is somewhere else, and completely unrelated. I’m assuming that you are throwing away the result value somewhere in between. Commented May 26, 2011 at 9:11

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.