Hi Prasanna
I had the same problem and have a solution, which does not use the
clipboard. Simply write your RTF text to a text file saved with a .rtf
extension. Then use the Selection.InsertFile method of the word
automation object. All your RTF formatting is retained as Word will
take care of the rtf decoding - presumably the reason for wanting to
use the clipboard in the first place.
Code extract:
//Sample rtf
string oSubText="{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose
02020603050405020304}Times New
Roman;}{\f35\fswiss\fcharset0\fprq2{\*\panose
020b0604030504040204}Verdana;}";
string sRTFFile=@"c:\test\insrtf.rtf"
SaveToTextFile(sRTFFile,oSubText,false);
//using word automation
Range range = oRange;
//Find tag to replace
range.Find.Execute(ref oFindText,
ref m_oMissing, ref m_oMissing, ref m_oMissing, ref m_oMissing, ref
m_oMissing,
ref m_oMissing, ref m_oWrap, ref m_oMissing, ref m_oMissing, ref
m_oMissing,
ref m_oMissing, ref m_oMissing, ref m_oMissing, ref m_oMissing);
m_oWord.Selection.Start = range.Start;
m_oWord.Selection.End = range.End;
//Insert RTF from file
m_oWord.Selection.InsertFile(sRTFFile,ref m_oMissing, ref
m_oMissing,ref oMissing, ref m_oMissing);
//Simple string to file function
public void SaveToTextFile(string sFile, string sOut,bool bAppend)
{
FileStream s;
StreamWriter w;
int i;
if(bAppend)
s = new FileStream(sFile,FileMode.Append);
else
s = new FileStream(sFile,FileMode.Create);
w = new StreamWriter(s);
w.Write(sOut);
w.Close();
}
Hope this helps you. Annoyingly this problem only ocurred on certain
machines and frankly I don't have the time to figure it out. The old
addage applies: "If it hurts stop doing it", so forget the clipboard
for now. It hurts too much!
Mulgara
"Prasanna Dsouza" <prasanna.DeleteThis@irislogic.com> wrote in message news:<#iAV$6ffEHA.708@TK2MSFTNGP09.phx.gbl>...
> Hi Tom
>
> I am using the following Statement
> System.Windows.Forms.IDataObject temp =
> System.Windows.Forms.Clipboard.GetDataObject();
>
> I get the Exception The Clipboard operation failed
> The function that contains the statement runs under a STA thread.
>
> My web service code does the following
> based on a document id, RTF content is fetched from the database.
> A word document is created.
> The RTF content is set to the Clipboard using the IDataObject retrieved
> using the statement System.Windows.Forms.Clipboard.GetDataObject();
>
> then using this statement
> p_oTempWordDoc.Range(ref l_oMissing,ref l_oMissing).Paste the rtf content is
> pasted to the word document. this document is saved and then sent to the
> client (that is the URL to the document)
>
> This is the statement that fails
> System.Windows.Forms.Clipboard.GetDataObject();
> It same code works correctly on Win2k server with IIS5.0 Wonder what could
> be the reason for not working in WIN2K3 and IIS6
>
> Thanks
>
> "Tom Kaminski [MVP]" <tomk (A@T) mvps (D.O.T) org> wrote in message
> news:cevvqv$4cc21@kcweb01.netnews.att.com...
> > "Prasanna Dsouza" <prasanna.DeleteThis@irislogic.com> wrote in message
> > news:egtbZD7eEHA.712@TK2MSFTNGP09.phx.gbl...
> > > Hi
> > > I cannot access clipboard for setting or getting data in my Web
> Application.
> > > Does it have anything to do with security.
> > > Where should i make changes, Local Security Policy, what rights are
> > > required for accesing Clipboard
> >
> > Exactly how are you trying to access the Clipboard from your web app?
> >
> > --
> > Tom Kaminski IIS MVP
<font color=green> > > <a style='text-decoration: underline;' href="http://www.microsoft.com/windowsserver2003/community/centers/iis/</font" target="_blank">http://www.microsoft.com/windowsserver2003/community/centers/iis/</font</a>>
<font color=green> > > <a style='text-decoration: underline;' href="http://mvp.support.microsoft.com/</font" target="_blank">http://mvp.support.microsoft.com/</font</a>>
<font color=green> > > <a style='text-decoration: underline;' href="http://www.iisfaq.com/</font" target="_blank">http://www.iisfaq.com/</font</a>>
> > <a style='text-decoration: underline;' href="http://www.iistoolshed.com/" target="_blank">http://www.iistoolshed.com/</a> - tools, scripts, and utilities for running
> IIS
<font color=green> > > <a style='text-decoration: underline;' href="http://www.tryiis.com</font" target="_blank">http://www.tryiis.com</font</a>>
> >
> ><!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: Clipboard Access + IIS6.0 + Win2003