An array of C#, PHP, and HTML programming articles, tutorials, and resources

Posts Tagged ‘ exists ’

While migrating an old application from Visual Studio 2003 to Visual Studio 2008, I came across what seemed to be a dll mismatch error. I had to remove the original dll from the references because of conflicts with the new 3.5 framework to a new version of the dll as found in the 3rd party clients default installation location (somewhere in C:\Program Files). After this change, visits to a page that utilizes the 3rd party dll would crash with this error (where dll1 was the temporary location of the original dll and dll2 was the temporary location of the new dll):

CS0433: The type exists in both [dll1] and [dll2]

The old dll temporary location was at C:\Windows\Microsoft.NET\Framework\v1.0.3705\Temporary ASP.NET Files and the new dll temporary location was at C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files. Note that these locations will vary depending on the Microsoft.NET framework version you are using.

My first thought was that the temporary location somehow got out of sync, so I decided to rebuild the solution, but this was unsuccessful. My next idea was the delete both temporary folders, but had problems because the folders were locked. The last thing I tried was to manually add a copy of the dll to the Solution’s bin folder and reference that specific copy. This fixed the problem!

Web applications often involve reading from and writing to files local to the web application server. In the case of reading from a file, errors may occur if the proper checks are not in place. One popular way of insuring errors don’t occur during runtime is to check if a file exists before attempting to read the file.

if (File.Exists("C:\\testfile.txt"))
{
   return true;
}
else
{
   return false;
}

This method utilizes the Exists function, part of the File class, to check if a file can be found at the specified directory. The string must be reachable from the server on which the web application resides. When expressing the input string, be sure to properly format your directory and file with double back slashes. To use File.Exists, be sure to include the following at the top of your file.

using System.IO;