明輝手游網(wǎng)中心:是一個免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

桌面端的移動運(yùn)算(3)

[摘要]Moving Files on a Device也許你會遇到需要在設(shè)備上移動或者重命名一個文件的情況。例如,你也許想在拷貝一個新版本的文件到設(shè)備上之前先為配置文件做一個備份。該功能的演示界面如圖2。...
Moving Files on a Device
也許你會遇到需要在設(shè)備上移動或者重命名一個文件的情況。例如,你也許想在拷貝一個新版本的文件到設(shè)備上之前先為配置文件做一個備份。該功能的演示界面如圖2。


Figure 2. The Move File tab of the RAPI demo program

OpenNETCF.Desktop.Communication命名空間RAPI類提供了MoveDeviceFile方法用于移動或重命名一個文件。作為CopyFile方法,這個方法將源文件作為第一個參數(shù),將目的文件作為第二個參數(shù)。

BtnMovePerform按鈕的點(diǎn)擊事件過程演示了MoveDeviceFile方法。

[VC#.NET]
private void btnMovePerform_Click(object sender, System.EventArgs e)
{
// Perform the move.
try
{
if ((txtMoveSource.Text == "") (txtMoveDestination.Text == ""))
{
MessageBox.Show("You must provide both a source and destination
file.",
"Missing File Information");
}
else
{
myrapi.MoveDeviceFile(txtMoveSource.Text, txtMoveDestination.Text);
MessageBox.Show("Your file has been copied.","Copy Success");
}
}

// Handle any errors that might occur.
catch (Exception ex)
{
MessageBox.Show("The following error occurred moving the file " +
ex.Message,"Connection Error");
}

}
[VB.NET]
Private Sub btnMovePerform_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnMovePerform.Click

' Perform the move.
Try
If (txtMoveSource.Text = "") Or (txtMoveDestination.Text = "") Then
MessageBox.Show("You must provide both a source and destination
file.", _
"Missing File Information")
Exit Sub
End If

myrapi.MoveDeviceFile(txtMoveSource.Text, txtMoveDestination.Text)

MessageBox.Show("Your file has been copied.", "Copy Success")

' Handle any errors that might occur.
Catch ex As Exception
MessageBox.Show("The following error occurred moving the file -"
& ex.Message, _
"Move Error")
End Try

End Sub
Deleting Files from a Device
你會發(fā)現(xiàn)你會經(jīng)常在使用RAPI拷貝文件的同時使用刪除文件的方法。比如,你的桌面程序也許會從設(shè)備上拷貝一個應(yīng)用程序用來存儲數(shù)據(jù)的文件,然后在成功執(zhí)行拷貝任務(wù)的基礎(chǔ)上,正確轉(zhuǎn)換并從設(shè)備上刪除該文件,使移動應(yīng)用程序準(zhǔn)備開始重新刷新。該操作的界面如圖3。


Figure 3. The Delete File tab of the RAPI demo program

OpenNETCF.Desktop.Communication命名空間RAPI類提供DeleteDeviceFile方法用來刪除設(shè)備文件。你想刪除的文件作為該方法的第一個參數(shù)。

BtnDeletePerform按鈕的點(diǎn)擊事件演示了DeleteDeviceFile方法。

[VC#.NET]
private void btnDeletePerform_Click(object sender, System.EventArgs e)
{

// Perform the delete.
try
{
if (txtDeleteFile.Text == "")
{
MessageBox.Show("You must provide a file to delete.",
"No File Provided");
}
else
{
myrapi.DeleteDeviceFile(txtDeleteFile.Text);
MessageBox.Show("Your file has been deleted.", "Delete Success");
}
}

// Handle any errors that might occur.
catch (Exception ex)
{
MessageBox.Show("The following error occurred while deleting the
file -" +
ex.Message, "Delete Error");
}
}
[VB.NET]
Private Sub btnDeletePerform_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnDeletePerform.Click

' Perform the delete.
Try
If (txtDeleteFile.Text = "") Then
MessageBox.Show("You must provide a file to delete.", _
"No File Provided")
Exit Sub
End If

myrapi.DeleteDeviceFile(txtDeleteFile.Text)

MessageBox.Show("Your file has been deleted.", "Delete Success")

' Handle any errors that might occur.
Catch ex As Exception
MessageBox.Show("The following error occurred while deleting the
file -" & ex.Message, _
"Delete Error")
End Try

End Sub
現(xiàn)在我們來回顧一下文件相關(guān)的三個方法:拷貝,移動和刪除。下面我們來看看如果從桌面程序中在設(shè)備上啟動一個應(yīng)用程序。