Issue regarding open word file and read only mode using c# & MS-word interop

i am programmatically open a word file for search and highlight keyword. my routine is working fine. the problem is when i am opening the file programmatically then a dialog come and ask me to open file in read only mode. the dialog look like below one
actually i do not want to open the file in read only mode because people can open and like to change and save. so guide me what i can do to not to open the file in read only mode.
here is my full code. just have a look and tell me what is wrong in my code or tell me any trick as a result i can open the file not in read only mode. here is my code.
private void button1_Click(object sender, EventArgs e)
            object fileName = "";
            string filePath = "";
            string strSaveasPath = "";
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
                fileName = openFileDialog1.FileName;
                //strSaveasPath = Path.GetDirectoryName(path.ToString());
            //fileName = "Z:\\C0000000003.doc";
            List<string> _list = new List<string>();
            _list.Add("tridip");
            _list.Add("arijit");
            //object fileName = "D:\\CVArchievePath\\C0000000001.doc";
            object textToFind = "test";
            object readOnly = false;
            Word.Application word = new Word.Application();
            Word.Document doc = new Word.Document();
            object missing = Type.Missing;
            try
                doc = word.Documents.Open(ref fileName, ref missing, ref readOnly,
                                          ref missing,
ref missing, ref missing,
                                          ref missing,
ref missing, ref missing,
                                          ref missing,
ref missing, ref missing,
                                          ref missing,
ref missing, ref missing,
                                          ref missing);
                doc.Activate();
                object matchPhrase = false;
                object matchCase = false;
                object matchPrefix = false;
                object matchSuffix = false;
                object matchWholeWord = false;
                object matchWildcards = false;
                object matchSoundsLike = false;
                object matchAllWordForms = false;
                object matchByte = false;
                object ignoreSpace = false;
                object ignorePunct = false;
                object highlightedColor = Word.WdColor.wdColorGreen;
                object textColor = Word.WdColor.wdColorLightOrange;
                object missingp = false;
                Word.Range range = doc.Range();
                foreach (string line in _list)
                    textToFind = line;
                    bool highlighted = range.Find.HitHighlight(ref textToFind,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing);
                System.Diagnostics.Process.Start(fileName.ToString());
            catch (Exception ex)
                Console.WriteLine("Error : " + ex.Message);
                //Console.ReadKey(true);
            finally
                //doc.Close(missing, missing, missing);
                if(doc!=null)
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(doc);
                if (word != null)
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(word);
                word = null;
                doc = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();

I know it's a very old issue and I reached to this page looking for a solution. Finally, I have found a fix to this problem.
The problem is that we create an instance of Word and do not close it correctly. This makes program believe that the file is already open and hence you're getting the respective message of file being locked by you.
Set the visibility of your application to true and then when you close it both file and instance should close and you will not get the problem again.

Similar Messages

  • I am not able to use Firefox with Sharepoint - I can only open a file in read-only mode and cannot checkout the document and edit.

    I would like to use Firefox with Sharepoint.
    However, I am only able to open a file in "read only" mode whch means I cannot edit the document and save it. I am also not able to "check-out" a document in Sharepoint and edit it at the same time.

    This may not work for everyone, but I solved this problem by clicking on the file name in sharepoint, not the document icon to the left of the name. This then brought up the various options, including checking out, editing, version history etc. It seems obvious but I have only just realised this!

  • Opening the file in read only mode

    hi all,
    i am using
    i want to open any type of files in read only mode using host command.so first i am setting the attribute to read only and then opening the file. But still the opened file is editable. i have written like below
    Host( 'cmd /c  attrib +r "\test_folder\testing\PURCHASE_ORDER\'||:PO_FILE_NAME||'"',NO_SCREEN);
    Host( 'cmd /c "\test_folder\testing\PURCHASE_ORDER\'||:PO_FILE_NAME||'"',NO_SCREEN);is this is the way to open the file in readonly mode?
    Along with the above the files which i opened with the help of above said code those files i am not able to delete also.(i have to delete the selected file)
    i thing when i am setting the attribute something is going for a mess!
    Please help.
    Thanks..
    Edited by: GD on Jun 23, 2011 2:25 AM

    hi,
    Read only means you cannot mofiy the file. This also includes that you cannot delete a readonly-file yes,
    what i am doing is i have three button in my layout 'save','view' and 'delete'.
    1.so when user press 'save' button after selecting the file then the file gets saved into the specified.
    2. when user press 'view' button the file has to open in read only mode.
    for this i have written above mentioned code(but still i am able to edit the file)
    3.when user press 'delete' button the file has to be deleted from the specified location.
    so my problem is after setting file to read only mode, i am able to edit but i am not able to delete it.
    What i am using to set the file to read only mode is right?
    Please help.
    Thanks..

  • Open MS word file in read only mode

    Hi All,
    Is there any function module or method to open an MS word file (which is not read only ) in read only mode.
    User should only be able to see the document ,he should not be able to make any changes.
    Regards,
    Mukul Sharma.

    Hi,
    Where is the document stored? In a content server? In BDS? In a directory?
    Regards,
    bert

  • Open pdf files in read-only mode

    Hi all,
    I want to open a file and I want to have option rewrite the file while it's open in the Reader.
    Is there any way how to open the file in the read-only mode and even from cmd in Windows?
    Thanks in advance.

    You can set security in the file to dissallow changesby going to File>Properties>Security in Acrobat. But you can't change anything with Reader.

  • Open a document in read only mode

    HI All,
    I created a panel in which we have
    edit box which shows the document path
    Browse button to allow a user to select an indesign document
    "Open read only" button.
    My requirement is that after selecting an Indesign document if user click to "OPen read only" button then it will opened selected document in read only mode.
    I will be highly thankfull to all community memeber if anyone can give me some hint to achieve this.
    Regards,
    Alam

    Alam,
    If you change the attributes of the file before opening it to read only the file will be opened as read only by Indesign. And then you could place a responder that could clear this read only flag when the file is being closed so that the permissions are restored to the original state.
    Manan Joshi
      - Efficient InDesign Solutions -
    MetaDesign Solutions
    http://metadesignsolutions.com/services/indesign-development.php

  • Opening a container in read-only mode (DB_RDONLY, setReadOnly())

    I have one process access a container in normal mode and another accessing it in read-only mode (XmlManager::openContainer with DB_RDONLY or XmlContainerConfig. setReadOnly(true) ), both with transactions. Is this:
    (1) wrong (potentially dangerous);
    (2) pointless (no benefits for the read-only process);
    (3) reasonable (potential benefits for the read-only process)?
    Whatever the answer, why is it so?
    Michael Ludwig

    hi,
    Read only means you cannot mofiy the file. This also includes that you cannot delete a readonly-file yes,
    what i am doing is i have three button in my layout 'save','view' and 'delete'.
    1.so when user press 'save' button after selecting the file then the file gets saved into the specified.
    2. when user press 'view' button the file has to open in read only mode.
    for this i have written above mentioned code(but still i am able to edit the file)
    3.when user press 'delete' button the file has to be deleted from the specified location.
    so my problem is after setting file to read only mode, i am able to edit but i am not able to delete it.
    What i am using to set the file to read only mode is right?
    Please help.
    Thanks..

  • Open EBS 115102 in read only mode

    Hi,
    I have upgraded our EBS 11510 to 1213 , on oracle 11202 DB.
    I have cloned a copy of the database and app. before the upgrade.
    I would like to give the end users an ability to open the old application and the db in read only mode.
    It is possible the open the application in read only mode ?
    If nnot what is my option the give an old-enchanged application to the end users , so they can compare diffs between old and new app ?
    Thanks
    Yoav

    Yoav wrote:
    Hi,
    I have upgraded our EBS 11510 to 1213 , on oracle 11202 DB.
    I have cloned a copy of the database and app. before the upgrade.
    I would like to give the end users an ability to open the old application and the db in read only mode.
    It is possible the open the application in read only mode ?
    If nnot what is my option the give an old-enchanged application to the end users , so they can compare diffs between old and new app ?
    Thanks
    YoavPlease see (Using Active Data Guard Reporting with Oracle E-Business Suite Release 12.1 and Oracle Database 11g [ID 1070491.1]).
    Thanks,
    Hussein

  • Office 2013 opens file in read only mode

    I have a client on Windows 8.1 Pro using Office 2013. When he access an office file from a network drive it opens in read only. When he saves the file to his desktop using save as it lets him open the file again in compatibility mode but he is unable to
    then overwrite the file on the network folder. It keeps giving him a permission error. I have deleted his profile, changed settings in office trust center settings and checked folder permisisons. I am out of ideas. Can anyone help me out here.
    Thanks

    Hi,
    Thanks for the reply.
    From the user, "Every file that I open, opens in read-only mode.  It appears that the security is set correctly and I have not changed anything, but, it does not allow it.  I have tried rebooting - not solved.  I tried disconnecting the shared drive and reconnecting - not solved.  However, when I do disconnect the mapped drive, I get a warning saying I have files open.  The problem occurs whether I access the files from the mapped drive or directly by drilling down through the folder structure." 
    When I try to move files over to the drive it says I do not have required permissions to overwrite or move a file. On a different computer he has full access but not on this one. Also the settings in trust center settings for file blocking and trusted locations
    also privacy.

  • Cannot open .jpg files; says read-only and no access

    I cannot open .jpg files I've been working on, even though I saved them as .jpg.  The prompt kept asking me to save the files over & over.  I did for a while then said NO to close the files.  Now it says access is denied.  Went to properties and tried to uncheck box for read-only, but it says I don't have access to do that.  How can I get my files back...these were very special photos.  Please help!

    No...just PSE7.  Unfortunately, when I tried to cut & paste the photos from
    my camera disk to my hard drive, the problem photo completely disappeared.
    When I go into recent history, the shortcuts are there, but none of them
    work.  They say the file has been moved or changed so...I don't even know
    where they are for now.  Do I need to call a repairman?

  • Opening old files on read-only volumes

    I do a lot of demos and presentations with (and about) Adobe Edge Animate, and discovered a flaw when opening files made by older versions, and stored on read-only media (like a remote public volume or folder). The file will open but Animate tries to "upgrade" it by immediately storing a (temporary) copy in the same location. This obviously won't work on locked or read-only media, so the application prompts there's a problem and the file cannot be used.
    Of course I can simply copy the whole folder to my desktop or another location which is write-enableb. But maybe this could be dealt with in a more elegant manner ?

    Hi Peter,
    Thank you for your post.
    We will test this issue and let you the result.
    Regards,
    Devendra

  • Need to open excel file and read comment field on ipad

    Hi,
    I need to open excel files on my ipad and read the comment fields that our ofiice wrote for me . But this doesn´t work .
    I tried it over several apps (office2HD, etc.) but with no result.
    It´s also necessary to work on our office google drive for me ..
    Can someone help me with this problem???
    BR
    Gunnar

    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename                = p_file
          i_begin_col             = 1
          i_begin_row             = 4
          i_end_col               = 12
          i_end_row               = 60000
        TABLES
          intern                  = it_excel
        EXCEPTIONS
          inconsistent_parameters = 1
          upload_ole              = 2
          OTHERS                  = 3.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      IF NOT it_excel[] IS INITIAL.
        SORT it_excel BY row col.
        LOOP AT it_excel.
          CASE it_excel-col.
            WHEN 1.
              it_file-hiden = it_excel-value.
            WHEN 2.
              it_file-budat = it_excel-value.
            WHEN 3.
              it_file-ltext = it_excel-value.
            WHEN 4.
              it_file-subsystem = it_excel-value.
            WHEN 5.
              it_file-work = it_excel-value.
            WHEN 6.
              it_file-role = it_excel-value.
            WHEN 7.
              it_file-sgtxt = it_excel-value.
            WHEN 8.
              it_file-company = it_excel-value.
            WHEN 9.
              it_file-megbtr = it_excel-value.
            WHEN 10.
              it_file-realbtr = it_excel-value.
            WHEN 11.
              it_file-comment = it_excel-value.
          ENDCASE.
          AT END OF row.
            APPEND it_file.
            CLEAR it_file.
          ENDAT.
        ENDLOOP.
      ELSE.
        MESSAGE i000  WITH 'The input file is empty'.
        STOP.
      ENDIF.

  • Error during open standby database in read only mode

    hi,
    alter database open read only;
    alter database open read only
    ERROR at line 1:
    ORA-10458: standby database requires recovery
    ORA-01152: file 1 was not restored from a sufficiently old backup
    ORA-01110: data file 1: '/u02/app/oracle/oradata/standby/system01.dbf'
    Detailed OCI error val is 12154 and errmsg is 'ORA-12154: TNS:could not resolve the connect identifier specified
    what is the reason of this.
    Thanks in advance.

    thanks for your reply.
    [oracle@standby admin]$ cat listener.ora
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.105.1.124)(PORT = 1521))
    LISTENER_STANDBY =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.105.1.124)(PORT = 1521))
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME =/opt/app/oracle/product/11.2.0/db_1)
    (PROGRAM = extproc)
    tnsfile
    [oracle@standby admin]$ cat tnsnames.ora
    standby =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =10.105.1.124)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = standby)
    ora11g =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =10.105.1.120)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = ora11g)
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.105.1.120)(PORT = 1521))
    EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    (CONNECT_DATA =
    (SID = PLSExtProc)
    (PRESENTATION = RO)
    pfile
    [oracle@standby standby]$ cat initstandby.ora
    ora11g.__db_cache_size=130023424
    ora11g.__java_pool_size=4194304
    ora11g.__large_pool_size=4194304
    ora11g.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
    ora11g.__pga_aggregate_target=146800640
    ora11g.__sga_target=276824064
    ora11g.__shared_io_pool_size=0
    ora11g.__shared_pool_size=121634816
    ora11g.__streams_pool_size=8388608
    *.audit_file_dest='/u01/app/oracle/admin/ora11g/adump'
    *.audit_trail='db'
    *.compatible='11.2.0.1.0'
    #*.control_files='/u02/app/ora11g/oradata/ora11g/control01.ctl','/u01/app/oracle/flash_recovery_area/ora11g/control02.ctl'
    *.db_block_size=8192
    *.db_domain=''
    *.db_name='ora11g'
    *.db_recovery_file_dest='/opt/app/oracle/flash_recovery_area'
    *.db_recovery_file_dest_size=4039114752
    *.diagnostic_dest='/opt/app/oracle'
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=ora11g)'
    *.memory_target=2016M
    *.open_cursors=300
    *.processes=150
    *.remote_login_passwordfile='EXCLUSIVE'
    *.undo_tablespace='UNDOTBS1'
    *.audit_file_dest='/opt/app/oracle/admin/standby/adump'
    *.audit_trail=none
    #*.background_dump_dest='/opt/app/oracle/admin/standby/bdump'
    #*.compatible='10.2.0.2.0'
    #*.control_files='/opt/app/oracle/oradata/standby/control01.ctl'
    #,'/opt/app/oracle/oradata/standby/control02.ctl','/opt/app/oracle/or
    *.control_files='/u02/app/oracle/oradata/standby/control_sb01.ctl'
    #,'/u02/app/oracle/oradata/standby/control_02.ctl','/u02/app/oracle/oradata/standby/control_03.ctl'
    *.core_dump_dest='/u01/app/oracle/diag/rdbms/standby/standby/cdump'
    *.db_block_size=8192
    *.db_domain=''
    *.db_file_multiblock_read_count=16
    #*.db_name='standby'
    #*.dispatchers='(PROTOCOL=TCP) (SERVICE=standby)'
    *.job_queue_processes=10
    *.log_archive_dest_1='location=/opt/app/oracle/arch'
    *.log_archive_config='dg_config=(standby,ora11g)'
    *.log_archive_dest_1='LOCATION=/opt/app/oracle/oradata/standby/archivelog'
    *.log_archive_dest_2='service=orcl valid_for=(online_logfiles,primary_role) db_unique_name=ora11g'
    *.log_archive_format='%t_%s_%r.dbf'
    *.standby_file_management=auto
    *.db_unique_name =standby
    *.fal_server='ora11g'
    *.fal_client='standby'
    *.service_names='standby'
    *.open_cursors=300
    *.pga_aggregate_target=525336576
    *.processes=1500
    *.remote_login_passwordfile='EXCLUSIVE'
    *.sga_target=1576009728
    *.undo_management='AUTO'
    *.undo_tablespace='undotbs02'
    #*.user_dump_dest='/opt/app/oracle/diag/rdbms/standby/standby/trace'
    *.standby_file_management ='manual'
    *.instance_name =standby
    #*.standby_archive_dest=/opt/app/oracle/oradata/standby/archivelog
    *.db_file_name_convert=(/u02/app/ora11g/oradata/ora11g,/u02/app/oracle/oradata/standby)
    *.log_file_name_convert='/u02/app/ora11g/oradata/ora11g','/u02/app/oracle/oradata/standby'
    #*.remote_listener=LISTENER_ora11g

  • How can I make a file not read only? Using LV6.0, I have tried the Access Rights VI w/o luck.

    I am talking about any file in windows 98 that has the read only box checked when I look at the properties of the file from Windows Explorer. I can can get rid of the check from the properties box, but I want to do it programmaticaly in LabView.

    Hi,
    Wire in '448' to the 'New Permissions' of the Access Rights VI. This will set the file as readable, writable and executable. I just tried this (on WinNT, though).
    The 'permissions' parameter is a 16-bit integer where the least 9 bits are used. Of these, for Windows, bits 8, 9, and 10 (0-indexed) are important (i.e. if these are set = integer 448). See online Help for full details.
    Hope this helps,
    Khalid

  • Tbs fragmentation and read only mode

    hello sir how can move table to read only
    and tbs fragmentation is performance problem or something else.
    plz. reply
    thanx in advance.

    hello sir how can move table to read onlyThere are no direct option where you can say table to read only.
    The workaround is to write a trigger to prevent insert,update & delete.
    tbs fragmentation is performance problem or something else.What is your defination for fragmentation? it depends.
    Which version of db you are using?
    If LMT is used, very less chances of fragmentation or if yuo can use uniform exten size for tablespaces, also very less chances.
    Jaffar

Maybe you are looking for

  • TabIndex not working in 2004 Pro

    Hi, I'm trying to get my tabIndex set up to tab through a series of buttons within a movie clip on my _root timeline. I have a movie clip called "menuoptions" on the _root then within that I have a number of buttons called "menu1" etc. I have tried t

  • Number of dialog process in SM50 does not tally RZ10

    Hi, I am encountering the above scenario whereby the number of dialog processes shown in SM50 is not the same as the profile parameters indicated in RZ10. I have restated SAP several times and it's still the same - both doesn't tally. Has anyone enco

  • Is there a quick way to fit everything in the Title/Action Safe Areas ?

    Hi, (sorry in advance for my english, I'm a french canadian) I built a complete DVD without realizing that I should consider the "Safe Areas" (see my first post : "Formatting in 4:3 but image is still stretched on a 4:3 TV. What the... ?"), so now I'

  • Performing arthmetic on generics

    Hi all, is it possible to do arithmetic operations in generic types? public <T,U,V> V add(T x, U y)  {        return x+y; }Edited by: jsunsnx on May 6, 2009 1:49 PM Edited by: jsunsnx on May 6, 2009 1:50 PM

  • Can anyone tell me how to change the names of the networks I have set up on Airport Express

    Can anyone tell me how to change the names of the networks I have set up on Airport Express please? I now work in a UN compound and my network is my own name, would prefer some anonymity so seeking to change the wifi network name that others might se