Reading File from Folder

  • Hi Guys,

    I Executed below Query in SQL server 2005

    DECLARE @FileName varchar(255)

    DECLARE @ExecCmd VARCHAR(255)

    DECLARE @y INT

    DECLARE @x INT

    DECLARE @FileContents VARCHAR(8000)

    CREATE TABLE #tempXML(PK INT NOT NULL IDENTITY(1,1), ThisLine VARCHAR(255))

    SET @FileName = '\\1.128.1.14\school\mlecontent\LMS\Contents\995_Module_LESSON I\imsmanifest.xml'

    SET @ExecCmd = 'type ' + @FileName

    SET @FileContents = ''

    EXEC master.dbo.xp_cmdshell @ExecCmd

    I got the Error as

    The system cannot find the file specified.

    Error occurred while processing: '\\1.128.1.14\school\mlecontent\LMS\Contents\995_Module_LESSON.

    The system cannot find the path specified.

    this error is because there is space in the folder name i e 995_Module_LESSON I so it is not able to read the file...

    Is there any way to read the file without renaming the Folder Name in System

    Thanks in Advance 🙂

  • Did you try using the escape character so that it treats space as a space???

  • Ignore the post, it seems to work only within Select.

  • The only thing that I can add, is that you shouldn't really be writing code around something that's already wrong. Rename the file and follow the same naming convention all the way through. E.g. File_Name, fileName, FileName

  • Hi Friend,

    I got the solution...

    DECLARE @FileName varchar(255)

    DECLARE @ExecCmd VARCHAR(255)

    DECLARE @y INT

    DECLARE @x INT

    DECLARE @FileContents VARCHAR(8000)

    CREATE TABLE #tempXML(PK INT NOT NULL IDENTITY(1,1), ThisLine VARCHAR(255))

    SET @FileName = '"\\1.128.1.14\school\mlecontent\LMS\Contents\995_Module_LESSON I\imsmanifest.xml"'

    SET @ExecCmd = 'type ' + @FileName

    SET @FileContents = ''

    EXEC master.dbo.xp_cmdshell @ExecCmd

Viewing 5 posts - 1 through 4 (of 4 total)

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