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

jao
  • 18,273
  • 15
  • 63
  • 96
  • Are you *sure* FilePath contains: `\\sharepoint\file.pdf` at the start? How are you testing the input / output values? – forsvarir May 26 '11 at 08:26
  • 1
    I tried your code and unable to replicate. Please check: http://imgur.com/09Iwq Did you define FilePath as described? – Alex R. May 26 '11 at 08:28
  • Related to [Regular Expressions ~ convert UNC to URL](http://stackoverflow.com/questions/1053300/regular-expressions-convert-unc-to-url) – Stefan May 26 '11 at 08:39
  • @forsvarir, @Alex, see updated question. I added pictures so you can see that it does change *something* – jao May 26 '11 at 08:45
  • @stefan, the code in the accepted answer does not work in my case (even when converted to VB.net) – jao May 26 '11 at 08:49
  • I'm a bit confused as to how your pictures are related to your code. If you put a breakpoint in your code, where you're doing the conversion, what's contained in `FilePath`. It may be that some escaping is necessary, "\\", or @"\"... – forsvarir May 26 '11 at 09:03
  • I thought it's _VB.net_. In your edit it appears to be _vbscript_. Checking... – Alex R. May 26 '11 at 09:08
  • @Alex R.: I assumed the function supplied was being used to help produce the VB script... – forsvarir May 26 '11 at 09:10
  • 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. – Konrad Rudolph May 26 '11 at 09:11
  • @forsvarir: Ok my bad, didn't read the code thoroughly. So it's still vb.net. But still unreproducible as my previous post. – Alex R. May 26 '11 at 09:14
  • Strange, it works for me: Dim FilePath = "\\Test.pdf" FilePath = Replace(FilePath, "\", "/") MsgBox(FilePath) Please check your text. Are you sure it is "\", or some character that have the visual like "\" character? – Luke Vo May 26 '11 at 10:17
  • it is vb.net that gets executed inside a vbscript – jao May 26 '11 at 11:24
  • @Konrad I think that is what went wrong, however I can only access part of the code as the rest of it is compiled in a DLL. See my answer below. It must've been something with throwing away the result (however, that does not explain why the http: still was added) – jao May 26 '11 at 11:33

1 Answers1

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

jao
  • 18,273
  • 15
  • 63
  • 96