Winforn中使用SaveFileDialog实现另存为对话框
場景
SaveFileDialog
命名空間:
System.Windows.Forms
提示用戶選擇文件的保存位置。 此類不能被繼承。
屬性
AddExtension?
獲取或設置一個值,該值指示如果用戶省略擴展名,對話框是否自動在文件名中添加擴展名。 (Inherited from FileDialog)
AutoUpgradeEnabled?
獲取或設置一個值,該值指示此 FileDialog 實例在 Windows Vista 上運行時是否應自動升級外觀和行為。 (Inherited from FileDialog)
CanRaiseEvents?
獲取一個指示組件是否可以引發事件的值。 (Inherited from Component)
CheckFileExists?
獲取或設置一個值,該值指示如果用戶指定不存在的文件名,對話框是否顯示警告。 (Inherited from FileDialog)
CheckPathExists?
獲取或設置一個值,該值指示如果用戶指定不存在的路徑,對話框是否顯示警告。 (Inherited from FileDialog)
Container?
獲取 IContainer,它包含 Component。 (Inherited from Component)
CreatePrompt?
獲取或設置一個值,該值指示如果用戶指定不存在的文件,對話框是否提示用戶允許創建該文件。
CustomPlaces?
獲取此 FileDialog 實例的自定義空間的集合。 (Inherited from FileDialog)
DefaultExt?
獲取或設置默認文件擴展名。 (Inherited from FileDialog)
DereferenceLinks?
獲取或設置一個值,該值指示對話框是否返回快捷方式引用的文件的位置,或者是否返回快捷方式 (.lnk) 的位置。 (Inherited from FileDialog)
DesignMode?
獲取一個值,用以指示 Component 當前是否處于設計模式。 (Inherited from Component)
Events?
獲取附加到此 Component 的事件處理程序的列表。 (Inherited from Component)
FileName?
獲取或設置一個包含在文件對話框中選定的文件名的字符串。 (Inherited from FileDialog)
FileNames?
獲取對話框中所有選定文件的文件名。 (Inherited from FileDialog)
Filter?
獲取或設置當前文件名篩選器字符串,該字符串決定對話框的“另存為文件類型”或“文件類型”框中出現的選擇內容。 (Inherited from FileDialog)
FilterIndex?
獲取或設置文件對話框中當前選定篩選器的索引。 (Inherited from FileDialog)
InitialDirectory?
獲取或設置文件對話框顯示的初始目錄。 (Inherited from FileDialog)
Instance?
獲取應用程序的 Win32 實例句柄。 (Inherited from FileDialog)
Options?
獲取用來初始化 FileDialog 的值。 (Inherited from FileDialog)
OverwritePrompt?
獲取或設置一個值,該值指示如果用戶指定的文件名已存在,Save As 對話框是否顯示警告。
RestoreDirectory?
獲取或設置一個值,該值指示該對話框在關閉前是否將目錄還原為之前選定的目錄。 (Inherited from FileDialog)
ShowHelp?
獲取或設置一個值,該值指示文件對話框中是否顯示“幫助”按鈕。 (Inherited from FileDialog)
Site?
獲取或設置 Component 的 ISite。 (Inherited from Component)
SupportMultiDottedExtensions?
獲取或設置對話框是否支持顯示和保存具有多個文件擴展名的文件。 (Inherited from FileDialog)
Tag?
獲取或設置一個對象,該對象包含控件的數據。 (Inherited from CommonDialog)
Title?
獲取或設置文件對話框標題。 (Inherited from FileDialog)
ValidateNames?
獲取或設置一個值,該值指示對話框是否只接受有效的 Win32 文件名。 (Inherited from FileDialog)
方法
CreateObjRef(Type)?
創建一個對象,該對象包含生成用于與遠程對象進行通信的代理所需的全部相關信息。 (Inherited from MarshalByRefObject)
Dispose()?
釋放由 Component 使用的所有資源。 (Inherited from Component)
Dispose(Boolean)?
釋放由 Component 占用的非托管資源,還可以另外再釋放托管資源。 (Inherited from Component)
Equals(Object)?
確定指定的對象是否等于當前對象。 (Inherited from Object)
GetHashCode()?
作為默認哈希函數。 (Inherited from Object)
GetLifetimeService()?
檢索控制此實例的生存期策略的當前生存期服務對象。 (Inherited from MarshalByRefObject)
GetService(Type)?
返回一個對象,該對象表示由 Component 或它的 Container 提供的服務。 (Inherited from Component)
GetType()?
獲取當前實例的 Type。 (Inherited from Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)?
定義要重寫的通用對話框掛鉤過程,以便向文件對話框添加特定功能。 (Inherited from FileDialog)
InitializeLifetimeService()?
獲取生存期服務對象來控制此實例的生存期策略。 (Inherited from MarshalByRefObject)
MemberwiseClone()?
創建當前 Object 的淺表副本。 (Inherited from Object)
MemberwiseClone(Boolean)?
創建當前 MarshalByRefObject 對象的淺表副本。 (Inherited from MarshalByRefObject)
OnFileOk(CancelEventArgs)?
引發 FileOk 事件。 (Inherited from FileDialog)
OnHelpRequest(EventArgs)?
引發 HelpRequest 事件。 (Inherited from CommonDialog)
OpenFile()?
打開用戶選定的具有讀/寫權限的文件。
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)?
定義要重寫的所有者窗口過程,以便向通用對話框添加特定功能。 (Inherited from CommonDialog)
Reset()?
將所有對話框選項重置為默認值。
RunDialog(IntPtr)?
指定通用對話框。 (Inherited from FileDialog)
ShowDialog()?
用默認的所有者運行通用對話框。 (Inherited from CommonDialog)
ShowDialog(IWin32Window)?
運行具有指定所有者的通用對話框。 (Inherited from CommonDialog)
ToString()?
提供此對象的字符串版本。 (Inherited from FileDialog)
事件
Disposed?
當通過調用 Dispose() 方法釋放組件時發生。 (Inherited from Component)
FileOk?
當用戶單擊文件對話框中的“打開”或 “保存”按鈕時發生。 (Inherited from FileDialog)
HelpRequest?
當用戶單擊通用對話框中的“幫助”按鈕時發生。 (Inherited from CommonDialog)
?
實現
? ???????? SaveFileDialog saveDialog = new SaveFileDialog();//設置默認文件擴展名。saveDialog.DefaultExt = "xls";//設置當前文件名篩選器字符串,該字符串決定對話框的“另存為文件類型”或“文件類型”框中出現的選擇內容。saveDialog.Filter = "Excel文件|*.xls";//設置文件名saveDialog.FileName = filename;//? 用默認的所有者運行通用對話框。saveDialog.ShowDialog();//如果修改了文件名,用對話框中的文件名名重新賦值filename = saveDialog.FileName;//被點了取消if (filename.IndexOf(":") < 0) return;//為文件提供 Stream,既支持同步讀寫操作,也支持異步讀寫操作。FileStream xlsfile = new FileStream(saveDialog.FileName, FileMode.Create);//excel寫入文件流excel.Write(xlsfile);//關閉文件流xlsfile.Close();//通過指定文檔或應用程序文件的名稱來啟動進程資源,并將資源與新的 Process 組件關聯。//即保存后打開ExcelSystem.Diagnostics.Process.Start(filename);效果
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Winforn中使用SaveFileDialog实现另存为对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VS中安装DevExpress后在Win
- 下一篇: Winform中实现文件另存为后并打开文