Author Topic: ReadDwgFile  (Read 1441 times)

0 Members and 1 Guest are viewing this topic.

WOWENS

  • Newt
  • Posts: 60
ReadDwgFile
« on: August 09, 2012, 11:40:05 AM »
is there a way to see if the drawing and or database is already open before using ReadDwgFile?

Humbertogo

  • Guest
Re: ReadDwgFile
« Reply #1 on: August 09, 2012, 12:44:41 PM »
with FileShare.Read

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: ReadDwgFile
« Reply #2 on: August 09, 2012, 01:43:17 PM »
This is the way I  check to see if any file is open before working on it.

Code: [Select]
private bool IsFileLocked(FileInfo file)
        {
            FileStream stream = null;
            try
            {
                stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            }
            catch (Exception)
            {
                return true;
            }
            finally
            {
                if (stream != null)
                    stream.Close();
            }
            return false;
        }

Then call it like.
Code: [Select]
if (IsFileLocked(new FileInfo(dwgName)))
{

}
Revit 2019, AMEP 2019 64bit Win 10

WOWENS

  • Newt
  • Posts: 60
Re: ReadDwgFile
« Reply #3 on: August 09, 2012, 02:21:01 PM »
thank you