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