/// <include file='doc\FileDialog.uex' path='docs/doc[@for="FileDialog.GetMultiselectFiles"]/*' /> /// <devdoc> /// Extracts the filename(s) returned by the file dialog. /// </devdoc> private string[] GetMultiselectFiles(CharBuffer charBuffer) { string directory = charBuffer.GetString(); string fileName = charBuffer.GetString(); if (fileName.Length == 0) { return new string[] { directory } } ; if (directory[directory.Length - 1] != '\\') { directory = directory + "\\"; } ArrayList names = new ArrayList(); do { if (fileName[0] != '\\' && (fileName.Length <= 3 || fileName[1] != ':' || fileName[2] != '\\')) { fileName = directory + fileName; } names.Add(fileName); fileName = charBuffer.GetString(); } while (fileName.Length > 0); string[] temp = new string[names.Count]; names.CopyTo(temp, 0); return(temp); }
/// <include file='doc\FileDialog.uex' path='docs/doc[@for="FileDialog.RunDialog"]/*' /> /// <devdoc> /// Implements running of a file dialog. /// </devdoc> /// <internalonly/> protected override bool RunDialog(IntPtr hWndOwner) { NativeMethods.WndProc hookProcPtr = new NativeMethods.WndProc(this.HookProc); NativeMethods.OPENFILENAME_I ofn = new NativeMethods.OPENFILENAME_I(); try { charBuffer = CharBuffer.CreateBuffer(FILEBUFSIZE); if (fileNames != null) { charBuffer.PutString(fileNames[0]); } ofn.lStructSize = Marshal.SizeOf(typeof(NativeMethods.OPENFILENAME_I)); // SECREVIEW : Assert environment so that we can determine // : the platform that we are running on. We only // : use the information to change the style of // : dialog, so it is safe. // IntSecurity.UnrestrictedEnvironment.Assert(); try { // Degrade to the older style dialog if we're not on Win2K. // We do this by setting the struct size to a different value // if (Environment.OSVersion.Platform != System.PlatformID.Win32NT || Environment.OSVersion.Version.Major < 5) { ofn.lStructSize = 0x4C; } } finally { CodeAccessPermission.RevertAssert(); } ofn.hwndOwner = hWndOwner; ofn.hInstance = Instance; ofn.lpstrFilter = MakeFilterString(filter); ofn.nFilterIndex = filterIndex; ofn.lpstrFile = charBuffer.AllocCoTaskMem(); ofn.nMaxFile = FILEBUFSIZE; ofn.lpstrInitialDir = initialDir; ofn.lpstrTitle = title; ofn.Flags = Options | (NativeMethods.OFN_EXPLORER | NativeMethods.OFN_ENABLEHOOK | NativeMethods.OFN_ENABLESIZING); ofn.lpfnHook = hookProcPtr; ofn.FlagsEx = NativeMethods.OFN_USESHELLITEM; if (defaultExt != null && AddExtension) { ofn.lpstrDefExt = defaultExt; } return(RunFileDialog(ofn)); } finally { charBuffer = null; if (ofn.lpstrFile != IntPtr.Zero) { Marshal.FreeCoTaskMem(ofn.lpstrFile); } } }