Hi there,
I used WinAPI function to create OLE file in C#. The WinAPI function is:
[DllImport("ole32.dll")]
public static extern int OleCreateFromFile(
[In] ref Guid rclsid,
[MarshalAs(UnmanagedType.LPWStr)] string lpszFileName,
[In] ref Guid riid, uint renderopt,
[In] IntPtr pFormatEtc,
IOleClientSite pClientSite,
IStorage pStg,
[MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);
I used this function in C# application as below:
hResult = OleAPI.OleCreateFromFile(ref clsid,
sourceFileFullPath,
ref IID_IOleObject,
(uint)OLERENDER.OLERENDER_DRAW,
IntPtr.Zero,
pOleClientSite,
pStorage,
out pOleObjectOut);
The function works perfectly. But when the length of filename of the file is 140, it failed to create OLE file. The return value of hResult is -2147467259.
The value of sourceFileFullPath="C:\Users\Administrator\AppData\Local\Temp\TmpTzStore1\pju3wswj.jmq\000008F6\CalendarRepeddsfsfdsfsfat344Issue5sdfdfsfsfdsfdsfsdsdfdsfsf00kbCalendarRepeatIssue500kbCalendarRepeatIssue500kbCalendarRepeatIssue500kb.xlsx"
The length of filename (CalendarRepeddsfsfdsfsfat344Issue5sdfdfsfsfdsfdsfsdsdfdsfsf00kbCalendarRepeatIssue500kbCalendarRepeatIssue500kbCalendarRepeatIssue500kb.xlsx) is 140.
But when I trimmed the file name to 120, it worked.
I wanted to know if there is any limitation in the filename length for OLE file. Since I tried it for different application files( doc,docx,txt,pdf...). The results varied for different files.
I don't know what is the exact the file name length that this API supports. Or it is dependent on the OS? I am using Windows Server 2008.
Thanks Prakash