SPFile.MoveTo method (String)
將檔案移至目的 URL,但不會覆寫相同名稱的現有檔案。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Sub MoveTo ( _
newUrl As String _
)
'用途
Dim instance As SPFile
Dim newUrl As String
instance.MoveTo(newUrl)
public void MoveTo(
string newUrl
)
參數
newUrl
Type: System.String指定目的地 URL 的字串。
Exceptions
Exception | Condition |
---|---|
SPException | 該名稱的檔案已經存在於指定的位置。 -或- 移動檔案時發生錯誤。 |
備註
MoveTo方法會將檔案移到同一個站台的另一個位置。
Examples
下列程式碼範例會將比指定日期還舊的檔案從一個資料夾移至另一個資料夾。
Dim site As SPSite = SPContext.Current.Site
Dim web As SPWeb = site.AllWebs("Site_Name/Subsite_Name")
Dim files As SPFileCollection = web.GetFolder("Source_Folder").Files
Dim i As Integer
For i = files.Count - 1 To 0 Step -1
If files(i).TimeCreated < Convert.ToDateTime
("12/01/2004 12:00:00 AM") Then
files(i).MoveTo("Destination_Folder/" & files(i).Name)
End If
Next i
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name/Subsite_Name"];
SPFileCollection collFiles = oWebsite.GetFolder("Source_Folder").Files;
for (int intIndex=collFiles.Count-1; intIndex>-1; intIndex--)
{
if (collFiles[intIndex].TimeCreated <
Convert.ToDateTime("12/01/2007 12:00:00 AM"))
{
collFiles[intIndex].MoveTo("Destination_Folder/" + collFiles[intIndex].Name);
}
}
oWebsite.Dispose();
![]() |
---|
某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects。 |