共用方式為


ITextDocument.SaveAs 方法 (String, Boolean, Boolean, IContentType)

將內容儲存TextBuffer到指定的檔案路徑。

命名空間:  Microsoft.VisualStudio.Text
組件:  Microsoft.VisualStudio.Text.Data (在 Microsoft.VisualStudio.Text.Data.dll 中)

語法

'宣告
Sub SaveAs ( _
    filePath As String, _
    overwrite As Boolean, _
    createFolder As Boolean, _
    newContentType As IContentType _
)
void SaveAs(
    string filePath,
    bool overwrite,
    bool createFolder,
    IContentType newContentType
)
void SaveAs(
    String^ filePath, 
    bool overwrite, 
    bool createFolder, 
    IContentType^ newContentType
)
abstract SaveAs : 
        filePath:string * 
        overwrite:bool * 
        createFolder:bool * 
        newContentType:IContentType -> unit
function SaveAs(
    filePath : String, 
    overwrite : boolean, 
    createFolder : boolean, 
    newContentType : IContentType
)

參數

  • filePath
    類型:String

    新檔案的名稱。

  • overwrite
    類型:Boolean

    如果應該覆寫 filePath (如果它存在的話),則為 true,否則為 false。

  • createFolder
    類型:Boolean

    如果應該建立包含 filePath 的資料夾 (如果它不存在的話),則為 true,否則為 false。

例外狀況

例外狀況 條件
InvalidOperationException

這個物件是引發事件的中間。

ArgumentNullException

filePath 或 newContentType 是 nullnull 參考 (即 Visual Basic 中的 Nothing)。

UnauthorizedAccessException

儲存檔案時發生存取錯誤。

IOException

發生 I/O 錯誤 (包括錯誤導因嘗試覆寫現存檔案時overwrite是false)。

ObjectDisposedException

這個物件已經過處置。

備註

如果另存為成功, FilePath設為filePath,和IsDirty設為false。 如果儲存失敗, FilePathIsDirty會保持不變。

成功的檔案另存新檔作業所引發的事件順序是FileActionOccurred後面加上ContentTypeChanged

.NET Framework 安全性

請參閱

參考

ITextDocument 介面

SaveAs 多載

Microsoft.VisualStudio.Text 命名空間