Пример #1
0
        private async Task <StorageFile> DoPickSingleFileAsync()
        {
            if (_filter.Count == 0)
            {
                throw new InvalidOperationException("The FileTypeFilters property must have at least one file type filter specified.");
            }

            NativeMethods.OPENFILENAME ofn = new Pickers.FileOpenPicker.NativeMethods.OPENFILENAME();

            StringBuilder sb = new StringBuilder();

            foreach (string ext in _filter)
            {
                sb.Append("*" + ext + "\0*" + ext + "\0");
            }

            sb.Append("\0");
            ofn.lpstrFilter = sb.ToString();
            ofn.lStructSize = Marshal.SizeOf(ofn);
            ofn.nMaxFile    = 256;
            ofn.lpstrFile   = new string('\0', ofn.nMaxFile);
            ofn.Flags       = 0x02001000;
            bool success = NativeMethods.GetOpenFileName(ref ofn);

            if (success)
            {
                return(new StorageFile(ofn.lpstrFile));
            }

            return(null);
        }
Пример #2
0
        private async Task<StorageFile> PickSingleFileAsyncImpl()
        {
            NativeMethods.OPENFILENAME ofn = new Pickers.FileOpenPicker.NativeMethods.OPENFILENAME();
            StringBuilder sb = new StringBuilder();
            foreach(string ext in _filter)
            {
                sb.Append("*" + ext + "\0*" + ext + "\0");
            }
            sb.Append("\0");
            ofn.lpstrFilter = sb.ToString();
            ofn.lStructSize = Marshal.SizeOf(ofn);
            ofn.nMaxFile = 256;
            ofn.lpstrFile = new string('\0', ofn.nMaxFile);
            ofn.Flags = 0x02001000;
            bool success = NativeMethods.GetOpenFileName(ref ofn);
            if(success)
            {
                return new StorageFile(ofn.lpstrFile);
            }

            return null;
        }