Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET General
Hi...
My task is to generate Word documents. By selecting the appropriate options, we can generate a document. I have the base documents in the server, and if I click generate, then the document will be generated and we can save it on our local drive.
 
If I am using the portal now and, at the same time, if some one is using it in their machine at the same time, then the document is not getting generated. Its automatically getting posted back.
 
I want to show a progress bar or something like that, so that the person waits until the document is completely generated.
 
Is this possible using threads?
Please Help with codes,
 
Thanks in advance,
Anusha
Posted 2-Oct-12 19:06pm
Edited 2-Oct-12 19:57pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

public void UpdateTOC(string file1, string file2)
        {
            using (var mainDoc = WordprocessingDocument.Open(file1, false))
            using (var resultDoc = WordprocessingDocument.Create(file2, WordprocessingDocumentType.Document))
            {
                // copy parts from source document to new document
                foreach (var part in mainDoc.Parts) resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId);
                // perform replacements in resultDoc.MainDocumentPart   // ... }
            }
 
        }
 
This is the code I am using.. File1 is the base document which will be in the server and file2 will be the document that will be generated.. both the documents have unique names..
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi Anusha,

 
You cannot do this unless the other entity which has the file open allows for shared reads.
 
for more ref:
 
http://stackoverflow.com/questions/897796/how-do-i-open-an-already-opened-file-with-a-net-streamreader[^]
 
regards
sarva
  Permalink  
v2
Comments
Sarrrva at 3-Oct-12 2:14am
   
Another one thread,
 
http://bytes.com/topic/c-sharp/answers/236171-reading-file-already-open-another-process
 
Regards
sarva
Anusha Sridhar at 3-Oct-12 2:17am
   
Hi Sarva,
Thanks for the link..
But I already tried the FileShare method and its not working..
Is it possible to do with theread.. Any idea about that?
Thanku. :)
Sarrrva at 3-Oct-12 2:31am
   
can you show me some sample?
regards
sarva
Sarrrva at 3-Oct-12 3:15am
   
you can try with thread mechanism,
 
Process.Start() & Process.WaitForExit()& Process.End,
Monitor.TryEnter, lock, using, and Deadlock
regards
sarva
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If file is being used by other process then you need to kill the process first before using the file. You need to see How to kill a process[^].
 
For some process, you'll require admin privileges to kill it. You'll have to take care of that also.
 
--Amit
  Permalink  
Comments
Anusha Sridhar at 3-Oct-12 2:24am
   
Hi Amit.. I don want to kill the other process..I want to wait till the other process completes. Because many people will be accessing the portal to generate the documents. I think killing wont be a good idea..
Thabks for the response. :)
_Amy at 3-Oct-12 2:37am
   
Then put your code inside try{}...catch(){} block. If any IO exception comes then show the message to user that "File is used by another application, try again later".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 271
1 OriginalGriff 253
2 nv3 60
3 Mehdi Gholam 45
4 VJ Reddy 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100