前言
提示:以下是本篇文章正文内容,下面案例可供参考
一、直接上代码
using System;
using System.Runtime.InteropServices;
/**************************************
日期:#CreateTime#
功能:Nothing
***************************************/
/// <summary>
/// 由于 extern 属性, 导致 只能放在AOT层。
/// </summary>
public class FileTool
{
/// <summary>
/// 保存文件
/// </summary>
/// <param name="fileExtension">文件后缀类型</param>
/// <param name="action"></param>
/// <param name="error"></param>
public static string SaveFolder(string fileExtension,Action error = null)
{
SaveFileDlg pth = new SaveFileDlg();
pth.structSize = Marshal.SizeOf(pth);
pth.dlgOwner = OpenFileDialog.GetForegroundWindow();
pth.filter = $"保存 (*{
fileExtension})\0*{
fileExtension}\0\0";
pth.file = new string(new char[256]);
pth.maxFile = pth.file.Length;
pth.fileTitle = new string(new char[64]);
pth.maxFileTitle = pth.fileTitle.Length;
pth.initialDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); //默认路径
pth.title = "保存文件";
//pth.dlgOwner =
pth.flags = 0x00080000 | 0x00001000 | 0x00000800