PC Review


Reply
Thread Tools Rate Thread

how to convert word doc to xml and store in database

 
 
chandu
Guest
Posts: n/a
 
      29th Aug 2006
Hello,

i need to convert a word doc into xml format and need to store that xml doc
in to a sqlserver database..
how to convert a word doc to xml and after retrieving that xml doc from
database table how to back to word form and place it in a doc..

thanks a lot..


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      29th Aug 2006
Changu,
From versions 2003 on, Word offers an option to Save As XML and will also
reload documents saved in this format.

If you are using the Word object model (requires a COM tab reference) in
your C# code, you can do this programmatically.

Storing in the database you would do as you would store any string of data.


Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"chandu" wrote:

> Hello,
>
> i need to convert a word doc into xml format and need to store that xml doc
> in to a sqlserver database..
> how to convert a word doc to xml and after retrieving that xml doc from
> database table how to back to word form and place it in a doc..
>
> thanks a lot..
>
>
>

 
Reply With Quote
 
joachim@yamagata-europe.com
Guest
Posts: n/a
 
      29th Aug 2006
Hi there

> i need to convert a word doc into xml format

MS Word has its own conversion to XML. I don't think it's possible to
write your own filter for
Word's proprietary format. So there's only one possibility, and that is
to use Word automation:
prepare for bugs and untold syntax secrets.

Here's some code that might help you - but I warn you, this whole thing
never
actually made it to my desktop ...

// Don't forget to add a reference to the Interop dll
using Word = Microsoft.Office.Interop.Word;
using System.Diagnostics;
using System.Runtime.InteropServices;

[DllImport("User32.dll")]
public static extern int ShowWindowAsync(IntPtr hWnd, int swCommand);

private void SaveAsXML(string filename)
{
Word.Application wordApp = new Word.Application();
// For reasons of performace and to avoid the user
// messing things up :
wordApp.Visible = false;
wordApp.ScreenUpdating = false;

// Word needs a lot of parameters that are optional in VB
// but need to be passed in C#
Object xmlFormat = Word.WdSaveFormat.wdFormatXML;
Object f = fileName;

wordApp.Documents.Open(
ref f,
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);

// Here comes the actual saving part
Word.Document doc = wordApp.ActiveDocument;
doc.SaveAs(
ref f,
ref xmlFormat,
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);

doc.Close(
ref missing,
ref missing,
ref missing);

CleanUpWordResources();
}

private void CleanUpWordresources()
{
// BUG: the COM proxy's reference (wordApp) seems to remain available
after
// the Word application has been closed. In order to avoid wordApp !=
null
// to throw an error it is safer to first look for running processes
// on OS level
processWord = Process.GetProcessesByName(PROCESS_WORD);
if (processWord.Length != 0)
{
if (wordApp != null)
{
//// Bring Application to front and close any open
WORD windows ////
foreach (Process p in processWord)
{
ShowWindowAsync(p.MainWindowHandle, (int)
ShowWindowConstants.SW_SHOWMAXIMIZED);
}


SetForegroundWindow(processWord[0].MainWindowHandle);

wordApp.Quit(ref missing, ref missing, ref
missing);
wordApp = null;
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}

private enum ShowWindowConstants : int
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_FORCEMINIMIZE = 11,
SW_MAX = 11
}

There's some redundant code that brings the Word App (should you decide
to make it visible
with its Visible propert to true) to the foreground and closes it (to
notify the user that somethings is happening). But I thought I you
might need it once you start messing around with Office automation.

Storing the xml into a database shouldn't be too difficult

Success!
Joachim Van den Bogaert

 
Reply With Quote
 
joachim@yamagata-europe.com
Guest
Posts: n/a
 
      29th Aug 2006
Sorry for havving messed up my formatting in the code above

 
Reply With Quote
 
JTC ^..^
Guest
Posts: n/a
 
      29th Aug 2006
"chandu" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Hello,
>
> i need to convert a word doc into xml format and need to store that
> xml doc in to a sqlserver database..
> how to convert a word doc to xml and after retrieving that xml doc
> from database table how to back to word form and place it in a doc..
>
> thanks a lot..
>
>


You can store your document as a BLOB in sql server. See the following
article.

http://www.microsoft.com/technet/pro...part3/c1161.ms
px?mfr=true

--
Regards
JTC ^..^
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Store Word document in access database automatically =?Utf-8?B?SGFycnk=?= Microsoft Access VBA Modules 3 22nd Mar 2007 05:29 PM
Is it possible to store word documents in an Access Database =?Utf-8?B?V2F5bmUgVmlsZXM=?= Microsoft Access 1 23rd Mar 2006 12:12 PM
How do I convert string field to an Int and Date fields to store the data in the database? Learner Microsoft ASP .NET 2 10th Mar 2006 08:25 PM
How do I convert Word document to Access Database? =?Utf-8?B?RUNhbmFsZXM=?= Microsoft Access 2 17th Oct 2005 08:51 PM
If is can store the chinese word to Database which is use Ms Acce. =?Utf-8?B?U3RldmVu?= Microsoft Access VBA Modules 0 23rd Oct 2004 10:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:22 AM.