none
How to set default "File Title" for Open/SaveAs file dialog OPENFILENAME RRS feed

  • Question

  • Hi,

    In .NET I'm using Win32 APIs OPENFILENAME to display Open/SaveAs file dialog (This was necessary to get the window handles). When open/saveAs file dialog is displayed I would want to display the default file title(in 'File name:' textbox). I tired this by setting 'lpstrFileTitle' but this does not seem work and 'File Name:' text box is empty.

    May I know How to set the default file tile in open/saveAs file dialog.

    Thanks

    Wednesday, December 7, 2016 7:28 PM

Answers

  • HI thisissuneel,

    Could you tell me what your project type is. It could better to help us your issue.

    >> I tired this by setting 'lpstrFileTitle' but this does not seem work and 'File Name:' text box is empty.

    According to OPENFILENAME document in MSDN

    lpstrFileTitle

    Type: LPTSTR

    The file name and extension (without path information) of the selected file. This member can be NULL.

    From above message, "lpstrFileTitle" is used by the selected file.

    I would suggest you "lpstrFile" instead.

    In addition, starting with Windows Vista Open and Save As common dialog boxes have been superseded by Common Item dialog.

    Here is I referred from MSDN document.

    [Starting with Windows Vista, the Open and Save As common dialog boxes have been superseded by the Common Item Dialog. We recommended that you use the Common Item Dialog API instead of these dialog boxes from the Common Dialog Box Library.]

    If you have other concern, please feel free to contact us.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Kristin Xie Thursday, December 8, 2016 2:53 AM
    • Proposed as answer by Kristin Xie Wednesday, December 14, 2016 1:10 AM
    • Marked as answer by thisissuneel Wednesday, December 28, 2016 5:29 AM
    Thursday, December 8, 2016 2:52 AM
  • Hi Kristin,

    Thanks for the help, Your suggestion worked.

    Instead of setting the "OPENFILENAME.FileTitle", I have set "OPENFILENAME.FileName" field with complete path and file name to be displayed in  'File name:' and it worked for me that displays suggested file name in "FileName:" textbox in Open/SaveAs file dialog.


    Thanks

    Suneel


    • Edited by thisissuneel Wednesday, December 28, 2016 5:30 AM
    • Marked as answer by thisissuneel Wednesday, December 28, 2016 5:30 AM
    Wednesday, December 28, 2016 5:29 AM

All replies

  • HI thisissuneel,

    Could you tell me what your project type is. It could better to help us your issue.

    >> I tired this by setting 'lpstrFileTitle' but this does not seem work and 'File Name:' text box is empty.

    According to OPENFILENAME document in MSDN

    lpstrFileTitle

    Type: LPTSTR

    The file name and extension (without path information) of the selected file. This member can be NULL.

    From above message, "lpstrFileTitle" is used by the selected file.

    I would suggest you "lpstrFile" instead.

    In addition, starting with Windows Vista Open and Save As common dialog boxes have been superseded by Common Item dialog.

    Here is I referred from MSDN document.

    [Starting with Windows Vista, the Open and Save As common dialog boxes have been superseded by the Common Item Dialog. We recommended that you use the Common Item Dialog API instead of these dialog boxes from the Common Dialog Box Library.]

    If you have other concern, please feel free to contact us.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Kristin Xie Thursday, December 8, 2016 2:53 AM
    • Proposed as answer by Kristin Xie Wednesday, December 14, 2016 1:10 AM
    • Marked as answer by thisissuneel Wednesday, December 28, 2016 5:29 AM
    Thursday, December 8, 2016 2:52 AM
  • The following will set the "File name" label to "Hello":

    using System;
    using System.Runtime.InteropServices;
    using System.Security;
    using HRESULT = System.UInt32;
    
    namespace ConsoleApplication1
    {
        class CustomOFD
        {
            #region Enums and Constants
            internal static class IID
            {
                /// <summary>IID_IAccessible</summary>
                public const string Accessible = "618736e0-3c3d-11cf-810c-00aa00389b71";
                /// <summary>IID_IEnumIDList</summary>
                public const string EnumIdList = "000214F2-0000-0000-C000-000000000046";
                /// <summary>IID_IEnumObjects</summary>
                public const string EnumObjects = "2c1c7e2e-2d0e-4059-831e-1e6f82335c2e";
                /// <summary>IID_IFileDialog</summary>
                public const string FileDialog = "42f85136-db7e-439c-85f1-e4075d135fc8";
                /// <summary>IID_IFileDialogEvents</summary>
                public const string FileDialogEvents = "973510DB-7D7F-452B-8975-74A85828D354";
                /// <summary>IID_IFileOpenDialog</summary>
                public const string FileOpenDialog = "d57c7288-d4ad-4768-be02-9d969532d960";
                /// <summary>IID_IFileSaveDialog</summary>
                public const string FileSaveDialog = "84bccd23-5fde-4cdb-aea4-af64b83d78ab";
                /// <summary>IID_IModalWindow</summary>
                public const string ModalWindow = "b4db1657-70d7-485e-8e3e-6fcb5a5c1802";
                /// <summary>IID_IObjectArray</summary>
                public const string ObjectArray = "92CA9DCD-5622-4bba-A805-5E9F541BD8C9";
                /// <summary>IID_IObjectCollection</summary>
                public const string ObjectCollection = "5632b1a4-e38a-400a-928a-d4cd63230295";
                /// <summary>IID_IPropertyStore</summary>
                public const string PropertyStore = "886d8eeb-8cf2-4446-8d02-cdba1dbdcf99";
                /// <summary>IID_IShellFolder</summary>
                public const string ShellFolder = "000214E6-0000-0000-C000-000000000046";
                /// <summary>IID_IShellLink</summary>
                public const string ShellLink = "000214F9-0000-0000-C000-000000000046";
                /// <summary>IID_IShellItem</summary>
                public const string ShellItem = "43826d1e-e718-42ee-bc55-a1e261c37bfe";
                /// <summary>IID_IShellItem2</summary>
                public const string ShellItem2 = "7e9fb0d3-919f-4307-ab2e-9b1860310c93";
                /// <summary>IID_IShellItemArray</summary>
                public const string ShellItemArray = "B63EA76D-1F85-456F-A19C-48159EFA858B";
                /// <summary>IID_ITaskbarList</summary>
                public const string TaskbarList = "56FDF342-FD6D-11d0-958A-006097C9A090";
                /// <summary>IID_ITaskbarList2</summary>
                public const string TaskbarList2 = "602D4995-B13A-429b-A66E-1935E44F4317";
                /// <summary>IID_IUnknown</summary>
                public const string Unknown = "00000000-0000-0000-C000-000000000046";
    
                #region Windows 7 interfaces
    
                /// <summary>IID_IApplicationDestinations</summary>
                public const string ApplicationDestinations = "12337d35-94c6-48a0-bce7-6a9c69d4d600";
                /// <summary>IID_IApplicationDocumentLists</summary>
                public const string ApplicationDocumentLists = "3c594f9f-9f30-47a1-979a-c9e83d3d0a06";
                /// <summary>IID_ICustomDestinationList</summary>
                public const string CustomDestinationList = "6332debf-87b5-4670-90c0-5e57b408a49e";
                /// <summary>IID_IObjectWithAppUserModelID</summary>
                public const string ObjectWithAppUserModelId = "36db0196-9665-46d1-9ba7-d3709eecf9ed";
                /// <summary>IID_IObjectWithProgID</summary>
                public const string ObjectWithProgId = "71e806fb-8dee-46fc-bf8c-7748a8a1ae13";
                /// <summary>IID_ITaskbarList3</summary>
                public const string TaskbarList3 = "ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf";
                /// <summary>IID_ITaskbarList4</summary>
                public const string TaskbarList4 = "c43dc798-95d1-4bea-9030-bb99e2983a1a";
    
                #endregion
            }
    
            internal static class CLSID
            {
                /// <summary>CLSID_EnumerableObjectCollection</summary>
                /// <remarks>IID_IEnumObjects.</remarks>
                public const string EnumerableObjectCollection = "2d3468c1-36a7-43b6-ac24-d3f02fd9607a";
                /// <summary>CLSID_FileOpenDialog</summary>
                /// <remarks>IID_IFileOpenDialog</remarks>
                public const string FileOpenDialog = "DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7";
                /// <summary>CLSID_FileSaveDialog</summary>
                /// <remarks>IID_IFileSaveDialog</remarks>
                public const string FileSaveDialog = "C0B4E2F3-BA21-4773-8DBA-335EC946EB8B";
                /// <summary>CLSID_ShellLink</summary>
                /// <remarks>IID_IShellLink</remarks>
                public const string ShellLink = "00021401-0000-0000-C000-000000000046";
                /// <summary>CLSID_TaskbarList</summary>
                /// <remarks>IID_ITaskbarList</remarks>
                public const string TaskbarList = "56FDF344-FD6D-11d0-958A-006097C9A090";
                /// <summary>CLSID_WebBrowser</summary>
                /// <remarks>IID_IWebBrowser2</remarks>
                public const string WebBrowser = "8856f961-340a-11d0-a96b-00c04fd705a2";
    
                #region Windows 7 classes
    
                /// <summary>CLSID_DestinationList</summary>
                /// <remarks>IID_ICustomDestinationList</remarks>
                public const string DestinationList = "77f10cf0-3db5-4966-b520-b7c54fd35ed6";
                /// <summary>CLSID_ApplicationDestinations</summary>
                /// <remarks>IID_IApplicationDestinations</remarks>
                public const string ApplicationDestinations = "86c14003-4d6b-4ef3-a7b4-0506663b2e68";
                /// <summary>CLSID_ApplicationDocumentLists</summary>
                /// <remarks>IID_IApplicationDocumentLists</remarks>
                public const string ApplicationDocumentLists = "86bec222-30f2-47e0-9f25-60d11cd75c28";
    
                #endregion
            }
    
            // IShellFolder::GetAttributesOf flags
            [Flags]
            internal enum SFGAO : uint
            {
                /// <summary>Objects can be copied</summary>
                /// <remarks>DROPEFFECT_COPY</remarks>
                CANCOPY = 0x1,
                /// <summary>Objects can be moved</summary>
                /// <remarks>DROPEFFECT_MOVE</remarks>
                CANMOVE = 0x2,
                /// <summary>Objects can be linked</summary>
                /// <remarks>
                /// DROPEFFECT_LINK.
                /// 
                /// If this bit is set on an item in the shell folder, a
                /// 'Create Shortcut' menu item will be added to the File
                /// menu and context menus for the item.  If the user selects
                /// that command, your IContextMenu::InvokeCommand() will be called
                /// with 'link'.
                /// That flag will also be used to determine if 'Create Shortcut'
                /// should be added when the item in your folder is dragged to another
                /// folder.
                /// </remarks>
                CANLINK = 0x4,
                /// <summary>supports BindToObject(IID_IStorage)</summary>
                STORAGE = 0x00000008,
                /// <summary>Objects can be renamed</summary>
                CANRENAME = 0x00000010,
                /// <summary>Objects can be deleted</summary>
                CANDELETE = 0x00000020,
                /// <summary>Objects have property sheets</summary>
                HASPROPSHEET = 0x00000040,
    
                // unused = 0x00000080,
    
                /// <summary>Objects are drop target</summary>
                DROPTARGET = 0x00000100,
                CAPABILITYMASK = 0x00000177,
                // unused = 0x00000200,
                // unused = 0x00000400,
                // unused = 0x00000800,
                // unused = 0x00001000,
                /// <summary>Object is encrypted (use alt color)</summary>
                ENCRYPTED = 0x00002000,
                /// <summary>'Slow' object</summary>
                ISSLOW = 0x00004000,
                /// <summary>Ghosted icon</summary>
                GHOSTED = 0x00008000,
                /// <summary>Shortcut (link)</summary>
                LINK = 0x00010000,
                /// <summary>Shared</summary>
                SHARE = 0x00020000,
                /// <summary>Read-only</summary>
                READONLY = 0x00040000,
                /// <summary> Hidden object</summary>
                HIDDEN = 0x00080000,
                DISPLAYATTRMASK = 0x000FC000,
                /// <summary> May contain children with SFGAO_FILESYSTEM</summary>
                FILESYSANCESTOR = 0x10000000,
                /// <summary>Support BindToObject(IID_IShellFolder)</summary>
                FOLDER = 0x20000000,
                /// <summary>Is a win32 file system object (file/folder/root)</summary>
                FILESYSTEM = 0x40000000,
                /// <summary>May contain children with SFGAO_FOLDER (may be slow)</summary>
                HASSUBFOLDER = 0x80000000,
                CONTENTSMASK = 0x80000000,
                /// <summary>Invalidate cached information (may be slow)</summary>
                VALIDATE = 0x01000000,
                /// <summary>Is this removeable media?</summary>
                REMOVABLE = 0x02000000,
                /// <summary> Object is compressed (use alt color)</summary>
                COMPRESSED = 0x04000000,
                /// <summary>Supports IShellFolder, but only implements CreateViewObject() (non-folder view)</summary>
                BROWSABLE = 0x08000000,
                /// <summary>Is a non-enumerated object (should be hidden)</summary>
                NONENUMERATED = 0x00100000,
                /// <summary>Should show bold in explorer tree</summary>
                NEWCONTENT = 0x00200000,
                /// <summary>Obsolete</summary>
                CANMONIKER = 0x00400000,
                /// <summary>Obsolete</summary>
                HASSTORAGE = 0x00400000,
                /// <summary>Supports BindToObject(IID_IStream)</summary>
                STREAM = 0x00400000,
                /// <summary>May contain children with SFGAO_STORAGE or SFGAO_STREAM</summary>
                STORAGEANCESTOR = 0x00800000,
                /// <summary>For determining storage capabilities, ie for open/save semantics</summary>
                STORAGECAPMASK = 0x70C50008,
                /// <summary>
                /// Attributes that are masked out for PKEY_SFGAOFlags because they are considered
                /// to cause slow calculations or lack context
                /// (SFGAO_VALIDATE | SFGAO_ISSLOW | SFGAO_HASSUBFOLDER and others)
                /// </summary>
                PKEYSFGAOMASK = 0x81044000,
            }
    
            /// <summary>FileDialog AddPlace options.  FDAP_*</summary>
            internal enum FDAP : uint
            {
                BOTTOM = 0x00000000,
                TOP = 0x00000001,
            }
    
            [Flags]
            internal enum FOS : uint
            {
                FOS_OVERWRITEPROMPT = 0x00000002,
                FOS_STRICTFILETYPES = 0x00000004,
                FOS_NOCHANGEDIR = 0x00000008,
                FOS_PICKFOLDERS = 0x00000020,
                FOS_FORCEFILESYSTEM = 0x00000040, // Ensure that items returned are filesystem items.
                FOS_ALLNONSTORAGEITEMS = 0x00000080, // Allow choosing items that have no storage.
                FOS_NOVALIDATE = 0x00000100,
                FOS_ALLOWMULTISELECT = 0x00000200,
                FOS_PATHMUSTEXIST = 0x00000800,
                FOS_FILEMUSTEXIST = 0x00001000,
                FOS_CREATEPROMPT = 0x00002000,
                FOS_SHAREAWARE = 0x00004000,
                FOS_NOREADONLYRETURN = 0x00008000,
                FOS_NOTESTFILECREATE = 0x00010000,
                FOS_HIDEMRUPLACES = 0x00020000,
                FOS_HIDEPINNEDPLACES = 0x00040000,
                FOS_NODEREFERENCELINKS = 0x00100000,
                FOS_DONTADDTORECENT = 0x02000000,
                FOS_FORCESHOWHIDDEN = 0x10000000,
                FOS_DEFAULTNOMINIMODE = 0x20000000
            }
    
            /// <summary>FDE_OVERWRITE_RESPONSE.  FDEOR_*</summary>
            internal enum FDEOR
            {
                DEFAULT = 0x00000000,
                ACCEPT = 0x00000001,
                REFUSE = 0x00000002,
            }
    
            /// <summary>FDE_SHAREVIOLATION_RESPONSE.  FDESVR_*</summary>
            internal enum FDESVR
            {
                DEFAULT = 0x00000000,
                ACCEPT = 0x00000001,
                REFUSE = 0x00000002,
            }
    
            /// <summary>ShellItem attribute flags.  SIATTRIBFLAGS_*</summary>
            internal enum SIATTRIBFLAGS
            {
                AND = 0x00000001,
                OR = 0x00000002,
                APPCOMPAT = 0x00000003,
            }
    
            /// <summary>
            /// SHELLITEMCOMPAREHINTF.  SICHINT_*.
            /// </summary>
            [Flags]
            internal enum SICHINT : uint
            {
                /// <summary>iOrder based on display in a folder view</summary>
                DISPLAY = 0x00000000,
                /// <summary>exact instance compare</summary>
                ALLFIELDS = 0x80000000,
                /// <summary>iOrder based on canonical name (better performance)</summary>
                CANONICAL = 0x10000000,
                /// <summary>Windows 7 and later.</summary>
                TEST_FILESYSPATH_IF_NOT_EQUAL = 0x20000000,
            }
    
            internal enum SIGDN : uint
            {
                SIGDN_NORMALDISPLAY = 0x00000000,           // SHGDN_NORMAL
                SIGDN_PARENTRELATIVEPARSING = 0x80018001,   // SHGDN_INFOLDER | SHGDN_FORPARSING
                SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000,  // SHGDN_FORPARSING
                SIGDN_PARENTRELATIVEEDITING = 0x80031001,   // SHGDN_INFOLDER | SHGDN_FOREDITING
                SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000,  // SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
                SIGDN_FILESYSPATH = 0x80058000,             // SHGDN_FORPARSING
                SIGDN_URL = 0x80068000,                     // SHGDN_FORPARSING
                SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8007c001,     // SHGDN_INFOLDER | SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
                SIGDN_PARENTRELATIVE = 0x80080001           // SHGDN_INFOLDER
            }
    
    
            #endregion
    
            #region Types and Interface
    
            internal struct PKEY
            {
                /// <summary>fmtid</summary>
                private readonly Guid _fmtid;
                /// <summary>pid</summary>
                private readonly uint _pid;
    
                private PKEY(Guid fmtid, uint pid)
                {
                    _fmtid = fmtid;
                    _pid = pid;
                }
    
                /// <summary>PKEY_Title</summary>
                public static readonly PKEY Title = new PKEY(new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"), 2);
                /// <summary>PKEY_AppUserModel_ID</summary>
                public static readonly PKEY AppUserModel_ID = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5);
                /// <summary>PKEY_AppUserModel_IsDestListSeparator</summary>
                public static readonly PKEY AppUserModel_IsDestListSeparator = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 6);
                /// <summary>PKEY_AppUserModel_RelaunchCommand</summary>
                public static readonly PKEY AppUserModel_RelaunchCommand = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 2);
                /// <summary>PKEY_AppUserModel_RelaunchDisplayNameResource</summary>
                public static readonly PKEY AppUserModel_RelaunchDisplayNameResource = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 4);
                /// <summary>PKEY_AppUserModel_RelaunchIconResource</summary>
                public static readonly PKEY AppUserModel_RelaunchIconResource = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 3);
            }
    
            [StructLayout(LayoutKind.Sequential)]
            public struct BIND_OPTS
            {
                public int cbStruct;
                public int grfFlags;
                public int grfMode;
                public int dwTickCountDeadline;
            }
    
            [Guid("0000000e-0000-0000-C000-000000000046")]
            [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
            [ComImport]
            public interface IBindCtx
            {
                void RegisterObjectBound([MarshalAs(UnmanagedType.Interface)] Object punk);
                void RevokeObjectBound([MarshalAs(UnmanagedType.Interface)] Object punk);
                void ReleaseBoundObjects();
                void SetBindOptions([In()] ref BIND_OPTS pbindopts);
                void GetBindOptions(ref BIND_OPTS pbindopts);
                void GetRunningObjectTable(out System.Runtime.InteropServices.ComTypes.IRunningObjectTable pprot);
                void RegisterObjectParam([MarshalAs(UnmanagedType.LPWStr)] String pszKey, [MarshalAs(UnmanagedType.Interface)] Object punk);
                void GetObjectParam([MarshalAs(UnmanagedType.LPWStr)] String pszKey, [MarshalAs(UnmanagedType.Interface)] out Object ppunk);
                void EnumObjectParam(out System.Runtime.InteropServices.ComTypes.IEnumString ppenum);
                [PreserveSig]
                int RevokeObjectParam([MarshalAs(UnmanagedType.LPWStr)] String pszKey);
            }
    
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            internal struct COMDLG_FILTERSPEC
            {
                [MarshalAs(UnmanagedType.LPWStr)]
                public string pszName;
                [MarshalAs(UnmanagedType.LPWStr)]
                public string pszSpec;
            }
    
            /// <SecurityNote>
            /// Critical: Suppresses unmanaged code security.
            /// </SecurityNote>
            [SecurityCritical(SecurityCriticalScope.Everything), SuppressUnmanagedCodeSecurity]
            [
                ComImport,
                InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
                Guid(IID.ShellItem),
            ]
            internal interface IShellItem
            {
                [return: MarshalAs(UnmanagedType.Interface)]
                object BindToHandler(IBindCtx pbc, [In] ref Guid bhid, [In] ref Guid riid);
    
                IShellItem GetParent();
    
                [return: MarshalAs(UnmanagedType.LPWStr)]
                string GetDisplayName(SIGDN sigdnName);
    
                uint GetAttributes(SFGAO sfgaoMask);
    
                int Compare(IShellItem psi, SICHINT hint);
            }
    
            /// <SecurityNote>
            /// Critical: Suppresses unmanaged code security.
            /// </SecurityNote>
            [SecurityCritical(SecurityCriticalScope.Everything), SuppressUnmanagedCodeSecurity]
            [
                ComImport,
                InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
                Guid(IID.ShellItemArray),
            ]
            internal interface IShellItemArray
            {
                [return: MarshalAs(UnmanagedType.Interface)]
                object BindToHandler(IBindCtx pbc, [In] ref Guid rbhid, [In] ref Guid riid);
    
                [return: MarshalAs(UnmanagedType.Interface)]
                object GetPropertyStore(int flags, [In] ref Guid riid);
    
                [return: MarshalAs(UnmanagedType.Interface)]
                object GetPropertyDescriptionList([In] ref PKEY keyType, [In] ref Guid riid);
    
                uint GetAttributes(SIATTRIBFLAGS dwAttribFlags, uint sfgaoMask);
    
                uint GetCount();
    
                IShellItem GetItemAt(uint dwIndex);
    
                [return: MarshalAs(UnmanagedType.Interface)]
                object EnumItems();
            }
    
            /// <SecurityNote>
            /// Critical: Suppresses unmanaged code security.
            /// </SecurityNote>
            [SecurityCritical(SecurityCriticalScope.Everything), SuppressUnmanagedCodeSecurity]
            [
                ComImport,
                InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
                Guid(IID.FileDialogEvents),
            ]
            internal interface IFileDialogEvents
            {
                [PreserveSig]
                HRESULT OnFileOk(IFileDialog pfd);
    
                [PreserveSig]
                HRESULT OnFolderChanging(IFileDialog pfd, IShellItem psiFolder);
    
                [PreserveSig]
                HRESULT OnFolderChange(IFileDialog pfd);
    
                [PreserveSig]
                HRESULT OnSelectionChange(IFileDialog pfd);
    
                [PreserveSig]
                HRESULT OnShareViolation(IFileDialog pfd, IShellItem psi, out FDESVR pResponse);
    
                [PreserveSig]
                HRESULT OnTypeChange(IFileDialog pfd);
    
                [PreserveSig]
                HRESULT OnOverwrite(IFileDialog pfd, IShellItem psi, out FDEOR pResponse);
            }
    
            /// <SecurityNote>
            /// Critical: Suppresses unmanaged code security.
            /// </SecurityNote>
            [SecurityCritical(SecurityCriticalScope.Everything), SuppressUnmanagedCodeSecurity]
            [
                ComImport,
                InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
                Guid(IID.ModalWindow),
            ]
            internal interface IModalWindow
            {
                [PreserveSig]
                HRESULT Show(IntPtr parent);
            }
    
            [SecurityCritical(SecurityCriticalScope.Everything), SuppressUnmanagedCodeSecurity]
            [
                ComImport,
                InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
                Guid(IID.FileDialog),
            ]
            internal interface IFileDialog : IModalWindow
            {
                #region IModalWindow redeclarations
                [PreserveSig]
                new HRESULT Show(IntPtr parent);
                #endregion
    
                void SetFileTypes(uint cFileTypes, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] COMDLG_FILTERSPEC[] rgFilterSpec);
    
                void SetFileTypeIndex(uint iFileType);
    
                uint GetFileTypeIndex();
    
                uint Advise(IFileDialogEvents pfde);
    
                void Unadvise(uint dwCookie);
    
                void SetOptions(FOS fos);
    
                FOS GetOptions();
    
                void SetDefaultFolder(IShellItem psi);
    
                void SetFolder(IShellItem psi);
    
                IShellItem GetFolder();
    
                IShellItem GetCurrentSelection();
    
                void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName);
    
                [return: MarshalAs(UnmanagedType.LPWStr)]
                string GetFileName();
    
                void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
    
                void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText);
    
                void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
    
                IShellItem GetResult();
    
                void AddPlace(IShellItem psi, FDAP alignment);
    
                void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
    
                void Close([MarshalAs(UnmanagedType.Error)] int hr);
    
                void SetClientGuid([In] ref Guid guid);
    
                void ClearClientData();
    
                void SetFilter([MarshalAs(UnmanagedType.Interface)] object pFilter);
            }
    
    
            [SecurityCritical(SecurityCriticalScope.Everything), SuppressUnmanagedCodeSecurity]
            [
                ComImport,
                InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
                Guid(IID.FileOpenDialog),
            ]
            internal interface IFileOpenDialog : IFileDialog
            {
                #region IFileDialog redeclarations
    
                #region IModalDialog redeclarations
                [PreserveSig]
                new HRESULT Show(IntPtr parent);
                #endregion
    
                new void SetFileTypes(uint cFileTypes, [In] COMDLG_FILTERSPEC[] rgFilterSpec);
                new void SetFileTypeIndex(uint iFileType);
                new uint GetFileTypeIndex();
                new uint Advise(IFileDialogEvents pfde);
                new void Unadvise(uint dwCookie);
                new void SetOptions(FOS fos);
                new FOS GetOptions();
                new void SetDefaultFolder(IShellItem psi);
                new void SetFolder(IShellItem psi);
                new IShellItem GetFolder();
                new IShellItem GetCurrentSelection();
                new void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName);
                [return: MarshalAs(UnmanagedType.LPWStr)]
                new void GetFileName();
                new void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
                new void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText);
                new void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
                new IShellItem GetResult();
                new void AddPlace(IShellItem psi, FDAP fdcp);
                new void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
                new void Close([MarshalAs(UnmanagedType.Error)] int hr);
                new void SetClientGuid([In] ref Guid guid);
                new void ClearClientData();
                new void SetFilter([MarshalAs(UnmanagedType.Interface)] object pFilter);
    
                #endregion
    
                IShellItemArray GetResults();
    
                IShellItemArray GetSelectedItems();
            }
    
            #endregion
    
            public static void Run()
            {
                IFileDialog ofd = (IFileDialog)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.FileOpenDialog)));
                ofd.SetFileNameLabel("Hello");
                ofd.Show(IntPtr.Zero);
    
            }
        }
    }


    Long code, but mostly interface declarations copied from ReferenceSource.
    Thursday, December 8, 2016 3:08 AM
    Answerer
  • HI thisissuneel,

    What's the problem now? Do you have any updates? Have you tried my suggestion?

    If you solved this issue, could you please also post here? It could be better for someone who has the same issue. Thanks for your cooperation and support.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 16, 2016 9:19 AM
  • Hi Kristin,

    Thanks for the help, Your suggestion worked.

    Instead of setting the "OPENFILENAME.FileTitle", I have set "OPENFILENAME.FileName" field with complete path and file name to be displayed in  'File name:' and it worked for me that displays suggested file name in "FileName:" textbox in Open/SaveAs file dialog.


    Thanks

    Suneel


    • Edited by thisissuneel Wednesday, December 28, 2016 5:30 AM
    • Marked as answer by thisissuneel Wednesday, December 28, 2016 5:30 AM
    Wednesday, December 28, 2016 5:29 AM