Hello Friends,
I want Application that displays an image preview of a Word document (Like thumbnail View of word document)
Following is my code but i got error on bold part of code
[code=vbnet]
Imports System
Imports System.Text
Imports System.Drawing. Imaging.BitmapD ata
Imports System.Runtime. InteropServices
Imports System.IO
Imports System.Web.UI.W ebControls.Imag e
Partial Class vb
Inherits System.Web.UI.P age
Public Shared Function GetThumbnailIma ge(ByVal fileName As String, ByVal longestEdge As Integer, ByVal colorDepth As Integer) As Image
Dim desktopFolder As IShellFolder
Dim someFolder As IShellFolder
Dim extract As IExtractImage
Dim pidl As IntPtr
Dim filePidl As IntPtr
Dim MAX_PATH As IntPtr
'Manually define the IIDs for IShellFolder and IExtractImage
Dim IID_IShellFolde r = New Guid("000214E6-0000-0000-C000-000000000046")
Dim IID_IExtractIma ge = New Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1")
'Divide the file name into a path and file name
Dim folderName = Path.GetDirecto ryName(fileName )
Dim shortFileName = Path.GetFileNam e(fileName)
'Get the desktop IShellFolder
ShellInterop.SH GetDesktopFolde r(desktopFolder )
'Get the parent folder IShellFolder
desktopFolder.P arseDisplayName (IntPtr.Zero, IntPtr.Zero, folderName, 0, pidl, 0)
desktopFolder.B indToObject(pid l, IntPtr.Zero, IID_IShellFolde r, someFolder)
'Get the file's IExtractImage
someFolder.Pars eDisplayName(In tPtr.Zero, IntPtr.Zero, shortFileName, 0, filePidl, 0)
someFolder.GetU IObjectOf(IntPt r.Zero, 1, filePidl, IID_IExtractIma ge, 0, extract)
'Set the size
Dim size As SIZE
size.cx = 500
size.cy = 500
Dim flags = IEIFLAG.ORIGSIZ E Or IEIFLAG.QUALITY
Dim bmp As IntPtr
Dim thePath = Marshal.AllocHG lobal(MAX_PATH)
'Interop will throw an exception if one of these calls fail.
Try
extract.GetLoca tion(thePath, MAX_PATH, 0, size, colorDepth, flags)
extract.Extract (bmp)
Catch ex As Exception
End Try
'Free the global memory we allocated for the path string
Marshal.FreeHGl obal(thePath)
'Free the pidls. The Runtime Callable Wrappers
'should automatically release the COM objects
Marshal.FreeCoT askMem(pidl)
Marshal.FreeCoT askMem(filePidl )
If Not bmp.Equals(IntP tr.Zero) Then
GetThumbnailIma ge = Image.FromHbitm ap(bmp)- Error (FromHbitmap is not a member of System.Web.UI.W ebControls.Imag e)
' GetThumbnailIma ge = Image(bmp)
Else
GetThumbnailIma ge = Nothing
End If
End Function
Public Enum IEIFLAG As Integer
ASYNC = &H1
CACHE = &H2
ASPECT = &H4
OFFLINE = &H8
GLEAM = &H10
SCREEN = &H20
ORIGSIZE = &H40
NOSTAMP = &H80
NOBORDER = &H100
QUALITY = &H200
End Enum
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure STRRET_CSTR
Public uType As Integer
<FieldOffset(4) , MarshalAs(Unman agedType.LPWStr )> _
Public pOleStr As String
<FieldOffset(4) > _
Public uOffset As Integer
<FieldOffset(4) , MarshalAs(Unman agedType.ByValA rray, SizeConst:=520) > _
Public strName As Byte()
End Structure
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure SIZE
Public cx As Integer
Public cy As Integer
End Structure
<ComImportAttri bute(), _
GuidAttribute(" BB2E617C-0920-11d1-9A0B-00C04FC2D6C1"), _
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
Public Interface IExtractImage
Sub GetLocation( _
ByVal pszPathBuffer As IntPtr, _
ByVal cch As Integer, _
ByRef pdwPriority As Integer, _
ByRef prgSize As SIZE, _
ByVal dwRecClrDepth As Integer, _
ByRef pdwFlags As Integer)
Sub Extract(ByRef phBmpThumbnail As IntPtr)
End Interface
<ComImportAttri bute(), _
GuidAttribute(" 000214E6-0000-0000-C000-000000000046"), _
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
Public Interface IShellFolder
Sub ParseDisplayNam e( _
ByVal hWnd As IntPtr, _
ByVal pbc As IntPtr, _
ByVal pszDisplayName As String, _
ByRef pchEaten As Integer, _
ByRef ppidl As System.IntPtr, _
ByRef pdwAttributes As Integer)
Sub EnumObjects( _
ByVal hwndOwner As IntPtr, _
<MarshalAs(Unma nagedType.U4)> ByVal grfFlags As Integer, _
<Out()> ByRef ppenumIDList As IntPtr)
Sub BindToObject( _
ByVal pidl As IntPtr, _
ByVal pbcReserved As IntPtr, _
ByRef riid As Guid, _
ByRef ppvOut As IShellFolder)
Sub BindToStorage( _
ByVal pidl As IntPtr, _
ByVal pbcReserved As IntPtr, _
ByRef riid As Guid, _
<Out()> ByVal ppvObj As IntPtr)
<PreserveSig( )> _
Function CompareIDs( _
ByVal lParam As IntPtr, _
ByVal pidl1 As IntPtr, _
ByVal pidl2 As IntPtr) As Integer
Sub CreateViewObjec t( _
ByVal hwndOwner As IntPtr, _
ByRef riid As Guid, _
ByVal ppvOut As Object)
Sub GetAttributesOf ( _
ByVal cidl As Integer, _
ByVal apidl As IntPtr, _
<MarshalAs(Unma nagedType.U4)> ByRef rgfInOut As Integer)
Sub GetUIObjectOf( _
ByVal hwndOwner As IntPtr, _
ByVal cidl As Integer, _
ByRef apidl As IntPtr, _
ByRef riid As Guid, _
<Out()> ByVal prgfInOut As Integer, _
<Out(), MarshalAs(Unman agedType.IUnkno wn)> ByRef ppvOut As Object)
Sub GetDisplayNameO f( _
ByVal pidl As IntPtr, _
<MarshalAs(Unma nagedType.U4)> ByVal uFlags As Integer, _
ByRef lpName As STRRET_CSTR)
Sub SetNameOf( _
ByVal hwndOwner As IntPtr, _
ByVal pidl As IntPtr, _
<MarshalAs(Unma nagedType.LPWSt r)> ByVal lpszName As String, _
<MarshalAs(Unma nagedType.U4)> ByVal uFlags As Integer, _
ByRef ppidlOut As IntPtr)
End Interface
Public Class ShellInterop
<DllImport("she ll32.dll", CharSet:=CharSe t.Auto)> _
Public Shared Function SHGetDesktopFol der( _
<Out()> ByRef ppshf As IShellFolder) As Integer
End Function
End Class
End Class
[/code]
If anyone has code that display word document in Thumbnail view then please send me code...
Thanx in Advance........ ..
I want Application that displays an image preview of a Word document (Like thumbnail View of word document)
Following is my code but i got error on bold part of code
[code=vbnet]
Imports System
Imports System.Text
Imports System.Drawing. Imaging.BitmapD ata
Imports System.Runtime. InteropServices
Imports System.IO
Imports System.Web.UI.W ebControls.Imag e
Partial Class vb
Inherits System.Web.UI.P age
Public Shared Function GetThumbnailIma ge(ByVal fileName As String, ByVal longestEdge As Integer, ByVal colorDepth As Integer) As Image
Dim desktopFolder As IShellFolder
Dim someFolder As IShellFolder
Dim extract As IExtractImage
Dim pidl As IntPtr
Dim filePidl As IntPtr
Dim MAX_PATH As IntPtr
'Manually define the IIDs for IShellFolder and IExtractImage
Dim IID_IShellFolde r = New Guid("000214E6-0000-0000-C000-000000000046")
Dim IID_IExtractIma ge = New Guid("BB2E617C-0920-11d1-9A0B-00C04FC2D6C1")
'Divide the file name into a path and file name
Dim folderName = Path.GetDirecto ryName(fileName )
Dim shortFileName = Path.GetFileNam e(fileName)
'Get the desktop IShellFolder
ShellInterop.SH GetDesktopFolde r(desktopFolder )
'Get the parent folder IShellFolder
desktopFolder.P arseDisplayName (IntPtr.Zero, IntPtr.Zero, folderName, 0, pidl, 0)
desktopFolder.B indToObject(pid l, IntPtr.Zero, IID_IShellFolde r, someFolder)
'Get the file's IExtractImage
someFolder.Pars eDisplayName(In tPtr.Zero, IntPtr.Zero, shortFileName, 0, filePidl, 0)
someFolder.GetU IObjectOf(IntPt r.Zero, 1, filePidl, IID_IExtractIma ge, 0, extract)
'Set the size
Dim size As SIZE
size.cx = 500
size.cy = 500
Dim flags = IEIFLAG.ORIGSIZ E Or IEIFLAG.QUALITY
Dim bmp As IntPtr
Dim thePath = Marshal.AllocHG lobal(MAX_PATH)
'Interop will throw an exception if one of these calls fail.
Try
extract.GetLoca tion(thePath, MAX_PATH, 0, size, colorDepth, flags)
extract.Extract (bmp)
Catch ex As Exception
End Try
'Free the global memory we allocated for the path string
Marshal.FreeHGl obal(thePath)
'Free the pidls. The Runtime Callable Wrappers
'should automatically release the COM objects
Marshal.FreeCoT askMem(pidl)
Marshal.FreeCoT askMem(filePidl )
If Not bmp.Equals(IntP tr.Zero) Then
GetThumbnailIma ge = Image.FromHbitm ap(bmp)- Error (FromHbitmap is not a member of System.Web.UI.W ebControls.Imag e)
' GetThumbnailIma ge = Image(bmp)
Else
GetThumbnailIma ge = Nothing
End If
End Function
Public Enum IEIFLAG As Integer
ASYNC = &H1
CACHE = &H2
ASPECT = &H4
OFFLINE = &H8
GLEAM = &H10
SCREEN = &H20
ORIGSIZE = &H40
NOSTAMP = &H80
NOBORDER = &H100
QUALITY = &H200
End Enum
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure STRRET_CSTR
Public uType As Integer
<FieldOffset(4) , MarshalAs(Unman agedType.LPWStr )> _
Public pOleStr As String
<FieldOffset(4) > _
Public uOffset As Integer
<FieldOffset(4) , MarshalAs(Unman agedType.ByValA rray, SizeConst:=520) > _
Public strName As Byte()
End Structure
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure SIZE
Public cx As Integer
Public cy As Integer
End Structure
<ComImportAttri bute(), _
GuidAttribute(" BB2E617C-0920-11d1-9A0B-00C04FC2D6C1"), _
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
Public Interface IExtractImage
Sub GetLocation( _
ByVal pszPathBuffer As IntPtr, _
ByVal cch As Integer, _
ByRef pdwPriority As Integer, _
ByRef prgSize As SIZE, _
ByVal dwRecClrDepth As Integer, _
ByRef pdwFlags As Integer)
Sub Extract(ByRef phBmpThumbnail As IntPtr)
End Interface
<ComImportAttri bute(), _
GuidAttribute(" 000214E6-0000-0000-C000-000000000046"), _
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
Public Interface IShellFolder
Sub ParseDisplayNam e( _
ByVal hWnd As IntPtr, _
ByVal pbc As IntPtr, _
ByVal pszDisplayName As String, _
ByRef pchEaten As Integer, _
ByRef ppidl As System.IntPtr, _
ByRef pdwAttributes As Integer)
Sub EnumObjects( _
ByVal hwndOwner As IntPtr, _
<MarshalAs(Unma nagedType.U4)> ByVal grfFlags As Integer, _
<Out()> ByRef ppenumIDList As IntPtr)
Sub BindToObject( _
ByVal pidl As IntPtr, _
ByVal pbcReserved As IntPtr, _
ByRef riid As Guid, _
ByRef ppvOut As IShellFolder)
Sub BindToStorage( _
ByVal pidl As IntPtr, _
ByVal pbcReserved As IntPtr, _
ByRef riid As Guid, _
<Out()> ByVal ppvObj As IntPtr)
<PreserveSig( )> _
Function CompareIDs( _
ByVal lParam As IntPtr, _
ByVal pidl1 As IntPtr, _
ByVal pidl2 As IntPtr) As Integer
Sub CreateViewObjec t( _
ByVal hwndOwner As IntPtr, _
ByRef riid As Guid, _
ByVal ppvOut As Object)
Sub GetAttributesOf ( _
ByVal cidl As Integer, _
ByVal apidl As IntPtr, _
<MarshalAs(Unma nagedType.U4)> ByRef rgfInOut As Integer)
Sub GetUIObjectOf( _
ByVal hwndOwner As IntPtr, _
ByVal cidl As Integer, _
ByRef apidl As IntPtr, _
ByRef riid As Guid, _
<Out()> ByVal prgfInOut As Integer, _
<Out(), MarshalAs(Unman agedType.IUnkno wn)> ByRef ppvOut As Object)
Sub GetDisplayNameO f( _
ByVal pidl As IntPtr, _
<MarshalAs(Unma nagedType.U4)> ByVal uFlags As Integer, _
ByRef lpName As STRRET_CSTR)
Sub SetNameOf( _
ByVal hwndOwner As IntPtr, _
ByVal pidl As IntPtr, _
<MarshalAs(Unma nagedType.LPWSt r)> ByVal lpszName As String, _
<MarshalAs(Unma nagedType.U4)> ByVal uFlags As Integer, _
ByRef ppidlOut As IntPtr)
End Interface
Public Class ShellInterop
<DllImport("she ll32.dll", CharSet:=CharSe t.Auto)> _
Public Shared Function SHGetDesktopFol der( _
<Out()> ByRef ppshf As IShellFolder) As Integer
End Function
End Class
End Class
[/code]
If anyone has code that display word document in Thumbnail view then please send me code...
Thanx in Advance........ ..
Comment