backslash problem in Script Task

  • Hi,

    Within a Script Task (editor) I have a simple routine which is:

    Public Sub Main()

    Dts.Variables("fileName").Value = System.IO.Path.GetFileName(Dts.Variables("fileName").Value.ToString())

    Dts.Variables("fullPath").Value = Dts.Variables("Location").Value.ToString() + Dts.Variables("fileName").Value.ToString()

    Dts.TaskResult = Dts.Results.Success

    End Sub

    The procedure will loop through/retreive each xml file name it finds and populate the variable [User::fileName] with this value (i.e. xxxx.xml).

    The package variables are all strings

  • [User::fileName] is defined as a blank ('')
  • [User::Location] is defined as '\\ServerName\xml\samples\'
  • [User::fullPath] is defined as a blank ('')
  • When the above task is complete (I notice via debug/watch), the fullPath is populated as

    '\\\\ServerName\\xml\\Samples\\xxxx.xml' - where the backslashes have been doubled-up

    I have discovered that SSIS can treat blackslashes as escape characters. How do I get around this to produce

    '\\ServerName\xml\Samples\xxxx.xml'?

    Thanks,

  • Quick suggestion - I'm not sure it will work though - just a shot in the dark really.

    Try defining the field value with a leading @ character - outside the quotes.

    [User::Location] = @"\\ServerName\xml\samples\"

  • SSIS has to double-up the slashes, so I don't think you need to worry about it.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • To avoid any confusion the [User::Location] variable was originally defined as \\pisces\ABN_Pub\siantec\samples

    - The single quotes surrounding this value were just to demonstrate the start and end of the field.

    If I add a @ at the start to this field I get

    Value@\\\\ServerName\\xml\\samples\\

  • Hi Wayne,

    Thanks for your reply

    Unfortunately, I do need to worry about it, as the value (with double backslashes) fails:

    ERROR: [XML Source [1]] Error: The component "XML Source" (1) was unable to read the XML data.

    However, if I type (or browse) \\ServerName\xml\samples\xxxx.xml it works

    Thanks,

  • Hi,

    I have resolved the issue. We had the 'Data access mode' set incorrectly.

    It was set to 'xml data from variable' which we have now replaced to 'xml file from variable'.

    An easy oversight.

    Thanks to all who spent time contributing.

  • Viewing 6 posts - 1 through 5 (of 5 total)

    You must be logged in to reply to this topic. Login to reply