System.IO File Exists in Infopath using Visual Studio.

T

Tina

I'm having a problem checking to see if a form already exists. We store
the forms using firstname lastname.xml. If the file exists I'd like to
concatenate a 1, or 2 etc after the filename.

strSaveLocation =
"http://longhorn/MIS New Revised User Request/";

strFileName = strSaveLocation + strFirstName + " " + strLastName + " "
+ intFileSuffix + ".xml";
where filesuffix will be 1, 2, 3 etc

if (File.Exists(strFileName)) - this line never finds the file, is it
somehting to do with my path(strSaveLocation)? Can I not look for the
file this way?

Thank you!
-Tina
 
B

Ben Walters

Hey Tina,
the object your using to check the file existinace File
is primarily a file system object, however your attempting to look for the
file at a http:// location, if the location your checking maps to a directory
on your Longhornserver then you could use a UNC path e.g. \\Server\Directory
to check for the file existence.

If your using a SharePoint form library then you will need to use the
SharePoint web services to check the forms existance

hope this helps
Cheers
Ben
 
L

Lance M

Hi Tina,

Ben is correct in how you are trying to access the files, however there
are more ways to access the files you are looking for than using the
webservices. You can use the Sharepoint DOM (document object model) to
drill down through your portal structure to find the files stored on
the server to see if they exist. The method is very similar to what you
were trying before, you just have to set up the instance of your portal
and then direct that to your form library. Something like this

TopologyManager topology = new TopologyManager();
PortalSite portal = topology.PortalSites[new
Uri("http://servername:potalNumber/")];
PortalContext context = PortalApplication.GetContext(portal);
SPWeb site = new SPWeb(context);

//then you declare form obejcts to look for the specific form

SPList list = site.Lists["listName"];
SPFormCollection forms = list.Forms;

//search through forms to find specific form.
 
Top