Checking for the existence of a file - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Checking for the existence of a file

Last post 12-11-2008 09:23 AM by PhDUltra. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-11-2008 08:40 AM

    Checking for the existence of a file

    I am using the code below to change the location of a Secondary data connection. This works fine but if the file does not exist, the FileQueryConnection.Execute() method generates an error of its own regardless of the Try block. I would like to avoid this error (confuses the users) by checking for the existence of the file before changing the FileQueryConnection object.

    Locating a local file would be easy but I have not been able to find a method of checking for the file on our SharePoint server using visual basic.

     

    If someone could point me in the right direction, I would be grateful.

     

    Dim myConnection As FileQueryConnection = Me.DataConnections("Project Charter")

    myConnection.FileLocation = strPath + "Project Charters/" & xnProjectName.Value.Trim & " Project Charter.xml"

     

    Try

    myConnection.Execute()

     

    Catch ex As Exception

    MessageBox.Show("File does not exist", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error)

     

    Exit Sub

    End Try

  • 12-11-2008 09:23 AM In reply to

    Re: Checking for the existence of a file

    To provide additional information that might be of value. If the xml file exist the code works just fine. If the xml file does not exist I get the following error messages before getting the "File does not exist" error in the Catch block:

     First i get:

    The internet address http://sharepointsite/Project Charters/ProjectName Project Charter.xml is not valid.

    After clicking on the OK button associated with this message, I get:

    To try to connect to other data sources, click “Try to connect”. To use previously stored data, click “Work Offline”.

    There are the three buttons: Work Offline, Try to Connect and Show Details. The detailed error message reads: The query cannot be run for the following DataObject: Project CharterInfoPath cannot run the specified query.The file is not a valid XML file.The file cannot be accessed.

    Thanks!

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.