Example #1
0
        public static void LoadUrl(ref HTMLDocument doc, String url, bool CreateSite)
        {
            if (doc == null)
            {
                throw new HtmlEditorException("Null document passed to LoadDocument");
            }

            if (CreateSite)
            {
                //set client site to DownloadOnlySite, to suppress scripts
                DownloadOnlySite ds = new DownloadOnlySite();
                IOleObject       ob = (IOleObject)doc;
                ob.SetClientSite(ds);
            }

            IPersistMoniker persistMoniker = (IPersistMoniker)doc;

            IMoniker moniker = null;

            int iResult = win32.CreateURLMoniker(null, url, out moniker);

            IBindCtx bindContext = null;

            iResult = win32.CreateBindCtx(0, out bindContext);

            iResult = persistMoniker.Load(0, moniker, bindContext, constants.STGM_READ);

            persistMoniker = null;

            bindContext = null;

            moniker = null;
        }
Example #2
0
        public static void LoadUrl(ref HTMLDocument doc, String url, bool CreateSite)
        {
            if (doc == null)
            {
                throw new HtmlEditorException("Null document passed to LoadDocument");
            }

            if (CreateSite)
            {
                //set client site to DownloadOnlySite, to suppress scripts
                DownloadOnlySite ds = new DownloadOnlySite();
                IOleObject ob = (IOleObject)doc;
                ob.SetClientSite(ds);
            }

            IPersistMoniker persistMoniker = (IPersistMoniker)doc;

            IMoniker moniker = null;

            int iResult = win32.CreateURLMoniker(null, url, out moniker);

            IBindCtx bindContext = null;

            iResult = win32.CreateBindCtx(0, out bindContext);

            iResult = persistMoniker.Load(0, moniker, bindContext, constants.STGM_READ);

            persistMoniker = null;

            bindContext = null;

            moniker = null;

        }
Example #3
0
        public static void LoadDocument(ref HTMLDocument doc, String documentVal, bool LoadAsAnsi, bool CreateSite, Encoding EncodingToAddPreamble)
        {
            if (doc == null)
            {
                throw new HtmlEditorException("Null document passed to LoadDocument");
            }

            IHTMLDocument2 htmldoc = (IHTMLDocument2)doc;

            bool isWin98 = (System.Environment.OSVersion.Platform == PlatformID.Win32Windows);

            if (documentVal == string.Empty)
            {
                documentVal = "<html></html>";
            }

            if (CreateSite)
            {
                //set client site to DownloadOnlySite, to suppress scripts
                DownloadOnlySite ds = new DownloadOnlySite();
                IOleObject       ob = (IOleObject)doc;
                ob.SetClientSite(ds);
            }

            IStream stream = null;

            if (isWin98 | LoadAsAnsi)
            {
                win32.CreateStreamOnHGlobal(Marshal.StringToHGlobalAnsi(documentVal), 1, out
                                            stream);
            }
            else
            {
                if (!isBOMPresent(documentVal))
                //add bytemark if needed
                {
                    if (EncodingToAddPreamble != null)
                    {
                        byte[] preamble      = EncodingToAddPreamble.GetPreamble();
                        String byteOrderMark = EncodingToAddPreamble.GetString(preamble, 0, preamble.Length);
                        documentVal = byteOrderMark + documentVal;
                    }
                }

                win32.CreateStreamOnHGlobal(Marshal.StringToHGlobalUni(documentVal), 1, out stream);
            }

            if (stream == null)
            {
                throw new HtmlEditorException("Could not allocate document stream");
            }


            if (isWin98)
            {
                //fix string termination on Win98
                ulong  thesize = 0;
                IntPtr ptr     = IntPtr.Zero;

                int iSizeOfInt64 = Marshal.SizeOf(typeof(Int64));
                ptr = Marshal.AllocHGlobal(iSizeOfInt64);

                if (ptr == IntPtr.Zero)
                {
                    throw new HtmlEditorException("Could not load document");
                }

                //seek to end of stream
                stream.Seek(0, 2, ptr);
                //read the size
                thesize = (ulong)Marshal.ReadInt64(ptr);
                //free the pointer
                Marshal.FreeHGlobal(ptr);

                //truncate the stream
                stream.SetSize((long)thesize);

                //2nd param, 0 is beginning, 1 is current, 2 is end

                if (thesize != (ulong)documentVal.Length + 1)
                {
                    //fix the size by truncating the stream
                    Debug.Assert(true, "Size of stream is unexpected", "The size of the stream is not equal to the length of the string passed to it.");
                    stream.SetSize(documentVal.Length + 1);
                }
            }

            //set stream to start

            stream.Seek(0, 0, IntPtr.Zero);
            //2nd param, 0 is beginning, 1 is current, 2 is end

            IPersistStreamInit persistentStreamInit = (IPersistStreamInit)
                                                      doc;

            if (persistentStreamInit != null)
            {
                int iRetVal = 0;
                iRetVal = persistentStreamInit.InitNew();
                if (iRetVal == HRESULT.S_OK)
                {
                    iRetVal = persistentStreamInit.Load(stream);

                    if (iRetVal != HRESULT.S_OK)
                    {
                        throw new HtmlEditorException("Could not load document");
                    }
                }
                else
                {
                    throw new HtmlEditorException("Could not load document");
                }
                persistentStreamInit = null;
            }
            else
            {
                throw new HtmlEditorException("Could not load document");
            }

            stream = null;
        }
Example #4
0
        public static void LoadDocument(ref HTMLDocument doc, String documentVal, bool LoadAsAnsi, bool CreateSite,Encoding EncodingToAddPreamble)
        {

            if (doc == null)
            {
                throw new HtmlEditorException("Null document passed to LoadDocument");
            }

            IHTMLDocument2 htmldoc = (IHTMLDocument2)doc;

            bool isWin98 = (System.Environment.OSVersion.Platform == PlatformID.Win32Windows);

            if (documentVal == string.Empty )
            {
                documentVal = "<html></html>";
            }

            if (CreateSite)
            {
                //set client site to DownloadOnlySite, to suppress scripts
                DownloadOnlySite ds = new DownloadOnlySite();
                IOleObject ob = (IOleObject)doc;
                ob.SetClientSite(ds);
            }

            IStream stream = null;

            if (isWin98 | LoadAsAnsi)
            {
                win32.CreateStreamOnHGlobal(Marshal.StringToHGlobalAnsi(documentVal), 1, out
					stream);
            }
            else
            {
                if (!isBOMPresent(documentVal))
                //add bytemark if needed
                {
                    if (EncodingToAddPreamble != null)
                    {
                        byte[] preamble = EncodingToAddPreamble.GetPreamble();
                        String byteOrderMark = EncodingToAddPreamble.GetString(preamble, 0, preamble.Length);
                        documentVal = byteOrderMark + documentVal;
                    }
                }

                win32.CreateStreamOnHGlobal(Marshal.StringToHGlobalUni(documentVal), 1, out stream);
            }

            if (stream == null)
            {
                throw new HtmlEditorException("Could not allocate document stream");
            }


            if (isWin98)
            {
                //fix string termination on Win98
                ulong thesize = 0;
                IntPtr ptr = IntPtr.Zero;

                int iSizeOfInt64 = Marshal.SizeOf(typeof(Int64));
                ptr = Marshal.AllocHGlobal(iSizeOfInt64);

                if (ptr == IntPtr.Zero)
                {
                    throw new HtmlEditorException("Could not load document");
                }

                //seek to end of stream
                stream.Seek(0, 2, ptr);
                //read the size
                thesize = (ulong)Marshal.ReadInt64(ptr);
                //free the pointer
                Marshal.FreeHGlobal(ptr);

                //truncate the stream
                stream.SetSize((long)thesize);

                //2nd param, 0 is beginning, 1 is current, 2 is end

                if (thesize != (ulong)documentVal.Length + 1)
                {
                    //fix the size by truncating the stream
                    Debug.Assert(true, "Size of stream is unexpected", "The size of the stream is not equal to the length of the string passed to it.");
                    stream.SetSize(documentVal.Length + 1);
                }

            }

            //set stream to start

            stream.Seek(0, 0, IntPtr.Zero);
            //2nd param, 0 is beginning, 1 is current, 2 is end

            IPersistStreamInit persistentStreamInit = (IPersistStreamInit)
                doc;

            if (persistentStreamInit != null)
            {
                int iRetVal = 0;
                iRetVal = persistentStreamInit.InitNew();
                if (iRetVal == HRESULT.S_OK)
                {
                    iRetVal = persistentStreamInit.Load(stream);
 
                    if (iRetVal != HRESULT.S_OK)
                    {
                        throw new HtmlEditorException("Could not load document");
                    }
                }
                else
                {
                    throw new HtmlEditorException("Could not load document");
                }
                persistentStreamInit = null;
            }
            else
            {
                throw new HtmlEditorException("Could not load document");
            }

            stream = null;
        }