c# - Access denied attempting to open a file on a shared folder -


i'm working on application has input folder receive files process. unfortunately, our costumer has choosen unix operational system run main software, , has shared folder can content through network. main software quite strange write files: firstly, creates file , writes content inside file. application i'm working on catchs file @ moment it's put inside folder , process file. in case, have "fight" accessing file, because main software writing content while application trying open see whether it's being used process. every time try open file, exception thrown, catch statement doesn't catch exception be.

the folowing code used when i'm trying open file see whether it's being used process:

public static void isopen(string file) {     bool isopen = true;      while (isopen)     {         try         {             using (file.open(file, filemode.open, fileaccess.read, fileshare.none))             {                 isopen = false;             }         }         catch (filenotfoundexception exp)         {             throw new exception(exp.message);         }         catch (directorynotfoundexception exp)         {             throw new exception(exp.message);         }         catch (ioexception)         {             isopen = true;             thread.sleep(500);         }     } } 

it looks file.open throwing exeception , handling inside method. have put logs on catchs statements see if it's working, i've written catch (exception), it's not working either.

when application tries open file, being used process, it's written message on event viewer: access path '<path here>' denied, , error log:

at system.io.__error.winioerror(int32 errorcode, string maybefullpath) @ system.io.filestream.init(string path, filemode mode, fileaccess access, int32 rights, boolean userights, fileshare share, int32 buffersize, fileoptions options, security_attributes secattrs, string msgpath, boolean bfromproxy, boolean uselongpath) @ system.io.filestream..ctor(string path, filemode mode, fileaccess access, fileshare share) @ utilities.isopen(string strfile) 

i think it's throwing unauthorizedaccessexception, application windows service, , when service restarted works properly, due content written inside file itself.

any ideas? thank you.

you need able cope situation. indeed getting unauthorizedaccessexception.

you need implement retry timeout situation.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -