private async Task <StorageFile> DoPickSaveFileAsync() { NativeMethods.OPENFILENAME ofn = new FileSavePicker.NativeMethods.OPENFILENAME(); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, IList <string> > item in FileTypeChoices) { sb.Append(item.Key + "\0"); foreach (string filetype in item.Value) { sb.Append("*" + filetype + ";"); } if (sb[sb.Length - 1] == ';') { sb.Length -= 1; } sb.Append('\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; if (!string.IsNullOrEmpty(DefaultFileExtension)) { ofn.lpstrDefExt = DefaultFileExtension.Substring(DefaultFileExtension.StartsWith(".") ? 1 : 0); } bool success = NativeMethods.GetSaveFileName(ref ofn); if (success) { File.Create(ofn.lpstrFile).Close(); return(new StorageFile(ofn.lpstrFile)); } return(null); }
private async Task<StorageFile> PickSaveFileAsyncImpl() { NativeMethods.OPENFILENAME ofn = new FileSavePicker.NativeMethods.OPENFILENAME(); StringBuilder sb = new StringBuilder(); foreach(KeyValuePair<string,IList<string>> item in FileTypeChoices) { sb.Append(item.Key + "\0"); foreach (string filetype in item.Value) { sb.Append("*" + filetype + ";"); } if(sb[sb.Length-1] == ';') { sb.Length -= 1; } sb.Append('\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; if(!string.IsNullOrEmpty(DefaultFileExtension)) { ofn.lpstrDefExt = DefaultFileExtension.Substring(DefaultFileExtension.StartsWith(".") ? 1 : 0); } bool success = NativeMethods.GetSaveFileName(ref ofn); if(success) { File.Create(ofn.lpstrFile).Close(); return new StorageFile(ofn.lpstrFile); } return null; }