G
Guest
We have run into an issue with a COM+ ServicedComponent What it does is
allows us to store a file to a network share from a web application. Here is
the code for the Save Routine:
[AutoComplete]
public bool SaveFile(string uncPath,string fileName, byte[] data)
{
FileStream nf;
try
{
if(!Directory.Exists(uncPath))
Directory.CreateDirectory(uncPath);
if (uncPath.Substring(uncPath.Length-1,1) != "/" &&
uncPath.Substring(uncPath.Length-1,1) != "\\")
{
uncPath += "/";
}
nf = new FileStream(uncPath + fileName,System.IO.FileMode.OpenOrCreate);
nf.Write(data,0,data.GetLength(0));
nf.Flush();
nf.Close();
return true;
}
catch(Exception myE)
{
throw myE;
}
}
The file gets uploaded to the server fine. However when we go to try and
remove it:
[AutoComplete]
public bool DeleteFile(string uncPath, string fileName)
{
try
{
if (uncPath.Substring(uncPath.Length-1,1) != "/" ||
uncPath.Substring(uncPath.Length-1,1) != "\\")
{
uncPath += "/";
}
File.Delete(uncPath + fileName);
return true;
}
catch (Exception ex)
{
return false;
}
}
It gives us an error. The error is a permission denied error:
Cannot delete <fileName>: It s being used by another person or program.
Close any programs that might be using the file and try again.
After a while like an hour or so I can go and delete the file. When I try
to delete it manually from the file system it gives the same error so the
error is not dot net specific. However the wierd thing is that I can modify
a text file no problem just cannot delete it.
Is there something I am missing in the COM+ component? I thought Close
should free up the resource and release it.
I am also doing a dispose on the Com+ component from the Web app code to try
and help but it don't.
Any ideas would be greatly appreciated as this is causing us major headaches.
allows us to store a file to a network share from a web application. Here is
the code for the Save Routine:
[AutoComplete]
public bool SaveFile(string uncPath,string fileName, byte[] data)
{
FileStream nf;
try
{
if(!Directory.Exists(uncPath))
Directory.CreateDirectory(uncPath);
if (uncPath.Substring(uncPath.Length-1,1) != "/" &&
uncPath.Substring(uncPath.Length-1,1) != "\\")
{
uncPath += "/";
}
nf = new FileStream(uncPath + fileName,System.IO.FileMode.OpenOrCreate);
nf.Write(data,0,data.GetLength(0));
nf.Flush();
nf.Close();
return true;
}
catch(Exception myE)
{
throw myE;
}
}
The file gets uploaded to the server fine. However when we go to try and
remove it:
[AutoComplete]
public bool DeleteFile(string uncPath, string fileName)
{
try
{
if (uncPath.Substring(uncPath.Length-1,1) != "/" ||
uncPath.Substring(uncPath.Length-1,1) != "\\")
{
uncPath += "/";
}
File.Delete(uncPath + fileName);
return true;
}
catch (Exception ex)
{
return false;
}
}
It gives us an error. The error is a permission denied error:
Cannot delete <fileName>: It s being used by another person or program.
Close any programs that might be using the file and try again.
After a while like an hour or so I can go and delete the file. When I try
to delete it manually from the file system it gives the same error so the
error is not dot net specific. However the wierd thing is that I can modify
a text file no problem just cannot delete it.
Is there something I am missing in the COM+ component? I thought Close
should free up the resource and release it.
I am also doing a dispose on the Com+ component from the Web app code to try
and help but it don't.
Any ideas would be greatly appreciated as this is causing us major headaches.