Desktop end mobile operation (3)

zhaozj2021-02-11  193

Moving file on a device

Maybe you will encounter the situation that needs to be moved or renamed on the device. For example, you may want to make a backup for the configuration file before copying a new version of the file to the device. The demo interface of this feature is shown in Figure 2.

Figure 2. The Move File Tab of The Rapi Demo Program

The OpenNetcf.Desktop.communication Namespace RAPI class provides the MoveDeviceFile method for mobile or rename a file. As a copyFile method, this method uses the source file as the first parameter, which uses the destination file as the second parameter.

The clicking event process of the BTNMovePerform button demonstrates the MoveDeviceFile method.

[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"

EXMESSAGE, "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 exception

Messagebox.show ("The Following Error Occurred Moving The File -"

& ex.Message, _

"Move Error") End Try

End Sub

DELETING FILES from A Device

You will find that you will often use the RAPI copy file to use the delete file. For example, your desktop program may copy an application on the device to store the data file, and then correctly convert the file correctly on the basis of successful copy tasks, remove the file from the device, so that the mobile application is ready to start re-refreshing . The interface of this operation is shown in Figure 3.

Figure 3. The Delete File Tab of the Rapi Demo Program

The OpenNetcf.desktop.communication Namespace RAPI class provides the deleteDeviceFile method to delete the device file. The file you want to delete is the first parameter of the method.

Click Events of the BTndeleteperform button demonstrate the deleteDevicefile method.

[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 - "

EXMESSAGE, "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 exception

Messagebox.show ("The Following Error Occurred While Deleting The

File - "& ex.Message, _

"Delete error")

END TRY

End Sub

转载请注明原文地址:https://www.9cbs.com/read-5045.html

New Post(0)