|
-
July 23rd, 2012, 11:49 AM
#3
Re: C# windows 7 file locks where file is located on a network
In some cases yes. The files are copied to the network, and it's possible the user can re-copy them to the same directory depending on certain business circumstances.
In otherwords, they've opened the application, copied the files, rec'd a new CD with different data but same images. When it goes to delete the directory that they were copied too, it throws an exception when trying to delete the thumbs.db file. In most cases it will delete all the images but not the directory.
Here's the method I use, there's some logic that determines when this method is called, but the exception is caught in this method:
Code:
private string CreateBarcodeDirectory(string path, bool? isGreenScreen)
{
var returnPath = "";
try
{
// _barcode is set through the UI textbox
if (!string.IsNullOrEmpty(_barcode))
{
switch (path)
{
case @"\\isilon\ImageCapture\":
if (!Directory.Exists(path + _barcode.PadLeft(8, '0')))
{
if (isGreenScreen == true)
{
var greenDirectory = _barcode.PadLeft(8, '0') + @"\OriginalGreen\";
Directory.CreateDirectory(path + greenDirectory );
returnPath = path + greenDirectory;
}
else
{
Directory.CreateDirectory(path + _barcode.PadLeft(8, '0'));
returnPath = path + _barcode.PadLeft(8, '0');
}
}
else
{
Directory.Delete(path + _barcode.PadLeft(8, '0'), true);
if (isGreenScreen == true)
{
var greenDirectory = _barcode.PadLeft(8, '0') + @"\OriginalGreen\";
Directory.CreateDirectory(path + greenDirectory);
returnPath = path + greenDirectory;
}
else
{
Directory.CreateDirectory(path + _barcode.PadLeft(8, '0'));
returnPath = path + _barcode.PadLeft(8, '0');
}
}
break;
case @"\\isilon\DCImages\":
if (!Directory.Exists(path + _barcode))
{
Directory.CreateDirectory(path + _barcode);
returnPath = path + _barcode;
}
else
{
Directory.Delete(path + _barcode, true);
Directory.CreateDirectory(path + _barcode);
returnPath = path + _barcode;
}
break;
default:
break;
}
}
}
catch (UnauthorizedAccessException uae)
{
OnError(uae, "Unable to access the path: " + path);
throw;
}
catch (Exception ex)
{
OnError(ex, "Error in CreateBarcodeDirectory(" + path + ")");
throw;
}
return returnPath;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|