Introduction
In this tutorial, we will build a simple application using the
wrapper library to create, move, copy, modify, and delete
files and folders. The application will need to point the
user to a URL to authorize the application, and from there,
we can easily access the user’s documents. We will use
the generic integration model, which effectively makes
SmartVault a basic file storage system similar to a
hard drive.
Here’s What You’ll Need
To perform autonomous authentication, we will first need to generate a RSA key pair. Visit Generating a Key Pair to view the steps on how to create them.
If you have not yet created a developer account or client ID, visit Creating a Developer Account to view the steps on how to create them.
Setting Up
You will also need to install the Java API wrapper library, begin communicating with SmartVault, and create a method to handle autonomous authentication. The following tutorial will guide you through this process:
Autonomous Authentication
Browsing the Folder Structure
A very common task in SmartVault is browsing the folder structure. For generic integrations, this is done using the /nodes/pth structure. The root of this structure contains the user’s accounts. Accounts contain vaults, and vaults contain folders. Folders are where files are typically stored.
Let’s create a method called browsePath to implement browsing this structure in a simplified way. This method will take in a path to browse and output the response. The variable children controls how deep in the structure we want to traverse on each call. Setting this to 1 will make the response contain the immediate contents of the path retrieved.
public NodeProto.NodeResponse browsePath(String path) throws Exception { int children = 1; // Immediate contents only return _delegation.navigate(path, children); }
Uploading Files
Let’s create a method called UploadFile to handle uploading files from the local computer to SmartVault. This method can take in a string containing the path to the file on the local machine and the path to folder in SmartVault where we want to store it.
public void uploadFile(String localFile, String remoteFolder) throws Exception { ... }
The first step with uploading a file is creating a Stream pointing to the file on the local computer. This stream will be read by the library and used to transmit the file’s data to SmartVault.
public void uploadFile(String localFile, String remoteFolder) throws Exception { FileInputStream stream = new FileInputStream(localFile); ... }
Now we need to build an UploadFileRequest in order to upload the file. This contains the file’s metadata, including the file name in SmartVault. For this example, we will use the same filename as used for the original file on the local computer.
public void uploadFile(String localFile, String remoteFolder) throws Exception { FileInputStream stream = new FileInputStream(localFile); UploadFileProto.UploadFileRequest.Builder builder = UploadFileProto.UploadFileRequest.newBuilder(); builder.setName(Paths.get(localFile).getFileName().toString()); ... }
Next, we need to actually upload the file, using a library call that takes in the request, the folder path to store it in, and the stream pointing to the file data.
public void uploadFile(String localFile, String remoteFolder) throws Exception { FileInputStream stream = new FileInputStream(localFile); UploadFileProto.UploadFileRequest.Builder builder = UploadFileProto.UploadFileRequest.newBuilder(); builder.setName(Paths.get(localFile).getFileName().toString()); _delegation.postFile(remoteFolder, builder.build(), stream); ... }
Finally, we’re going to want to close that stream.
public void uploadFile(String localFile, String remoteFolder) throws Exception { FileInputStream stream = new FileInputStream(localFile); UploadFileProto.UploadFileRequest.Builder builder = UploadFileProto.UploadFileRequest.newBuilder(); builder.setName(Paths.get(localFile).getFileName().toString()); _delegation.postFile(remoteFolder, builder.build(), stream); stream.close(); }
Creating Folders
Now we’ll create a method called createFolder to handle the creation of folders. This method will take in a the path in SmartVault where you want the folder to be located and the name that you want to give to the folder.
public void createFolder(String destination, String name) throws Exception { . . . }
All we need to do here is use a library call to create the folder that takes in the destination path and the name of the new folder.
public void createFolder(String destination, String name) throws Exception { _delegation.createFolder(destination, name); }
Moving a File
Now let’s create another method called moveFile, which will take in the path of the file you want to move and what you want the new path of the file to be.
public void moveFile(String fileToMove, String remoteFolder) throws Exception { . . . }
And simply place the library call that moves the folder and takes in the path of the file you want to move and the new file path.
public void moveFile(String fileToMove, String remoteFolder) throws Exception { _delegation.move(fileToMove, remoteFolder); }
Moving a Folder
Next, let’s create a method called moveFolder that takes in the path of the folder you want to move and the location where you want the folder.
public void moveFolder(String folderToMove, String remoteFolder) throws Exception { . . . }
Since we need to pass what you want the actual path of the moved folder to be, let’s create a new string called newPath which will hold this new path by concatenating the location where you want to place the folder and the name of the folder you are moving.
public void moveFolder(String folderToMove, String remoteFolder) throws Exception { remoteFolder = String.format( "%s/%s", remoteFolder, Paths.get(folderToMove).getFileName().toString() ); . . . }
Finally, let’s make the library call to move the folder, and pass the location of the folder you want to move and the new path of the folder.
public void moveFolder(String folderToMove, String remoteFolder) throws Exception { remoteFolder = String.format( "%s/%s", remoteFolder, Paths.get(folderToMove).getFileName().toString() ); _delegation.move(folderToMove, remoteFolder); }
Making a Copy
Next, we’ll make a method called copyFolder which will take in the path of the file or folder you want to copy, and the path, including the name, of the folder or file you want to copy.
public void copy(String toCopy, String remoteFolder) throws Exception { . . . }
And let’s just place the library call, which takes in the path of the folder or file you want to copy and the path of the new one.
public void copy(String toCopy, String remoteFolder) throws Exception { _delegation.copy(toCopy, remoteFolder); }
Modifying a Folder’s Properties
Let’s proceed to create a method called modifyFolder which will modify the properties of the folder. For this tutorial we will be updating the description. The method will take in the path of the folder you want to modify and the new description.
public void modifyFolder(String remoteFolder, String description) throws Exception { . . . }
Now make the library call, which takes in the path and the new description.
public void modifyFolder(String remoteFolder, String description) throws Exception { _delegation.modifyFolder(remoteFolder, description); }
Modifying a File’s Properties
Create a method called modifyFile, which will take in the path of the file whose properties you would like to update and the new description you would like to give it.
public void modifyFile(String remoteFile, String description) throws Exception { . . . }
Now make the library call to modify the file and pass the path and the new description.
public void modifyFile(String remoteFile, String description) throws Exception { _delegation.modifyFile(remoteFile, description); }
Deleting a File
Create a new method called deleteFile with one parameter—the path of the file you would like like to remove.
public void deleteFile(String remoteFile) throws Exception { . . . }
Now simply make the library call to delete the file and pass the path of the file.
public void deleteFile(String remoteFile) throws Exception { _delegation.deleteFile(remoteFile); }
Deleting a Folder
Lastly, let’s make a method called deleteFolder which will take in the path of the folder.
public void deleteFolder(String remoteFolder) throws Exception { . . . }
And simply make the library call to delete the file and send the path of the file that you want to remove.
public void deleteFolder(String remoteFolder) throws Exception { _delegation.deleteFile(remoteFolder); }
Trying It Out
Setting Up
Now that we’ve got a nice wrapper class to handle some basic operations, let’s try it out! We’re going to make a simple console program that uploads a file to SmartVault and downloads it again.
Let’s start with a simple main method.
public static void main(String[] args) { ... }
Opening the Connection
All we need to do is create an instance of our SmartVault class to open a connection.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); . . . } catch (Exception e) { e.printStackTrace(); } }
Authenticating
Include the authenticate method you created using the Autonomous Authentication tutorial.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); } catch (Exception e) { e.printStackTrace(); } }
Uploading a File
Before we can upload a file, we need two pieces of information: the path to the file on the local system, and the path in SmartVault where the file needs to be stored. Let’s call a new method called getLocalFile to get the local file path from the user.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); String localFile = getLocalFile(); ... } catch (Exception e) { e.printStackTrace(); } }
Now let’s implement the getLocalFile method. This will ask the user to input a file from the console.
private static String getLocalFile() { System.out.print("\nEnter the path to a file to upload. " + "(Hint: drag a file to the console window): "); String localFile = keyboard.nextLine(); return localFile.replace("\"", ""); // Remove quotes, if supplied }
Let’s go back to our main method and call a new method called getRemoteFolder to determine where to store the file in SmartVault. This method will take in the SmartVault instance we just created and the name of the folder you want to get the path of. For this tutorial, let’s assume that we’re going to upload the file to My First folder. If you have changed the name of this vault or folder in your account, you’ll probably want to update them here to match.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); String localFile = getLocalFile(); String remoteFolder = getRemoteFolder(smartVault, "My First folder"); ... } catch (Exception e) { e.printStackTrace(); } }
Now let’s implement getRemoteFolder. SmartVault automatically creates an account for the user on signup containing a vault called My First Vault and a folder called My First folder.
This still doesn’t give us the account name, which is randomly generated on signup. But we can use our browsePath method to retrieve it.
private static String getRemoteFolder(SmartVault smartVault, String folderName) throws Exception { NodeProto.NodeResponse rootNode = smartVault.browsePath("nodes/pth"); String account = rootNode.getMessage().getChildrenList().get(0).getName(); return String.format("/nodes/pth/%s/My First Vault/%s", account,folderName); }
Finally, we can actually upload the file using the uploadFile method we created earlier. Let’s do this in the main method.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); String localFile = getLocalFile(); String remoteFolder = getRemoteFolder(smartVault, "My First folder"); System.out.println(String.format("\nUploading '%s' to '%s'", localFile, remoteFolder)); smartVault.uploadFile(localFile, remoteFolder); System.out.println("\nUpload complete"); . . . } catch (Exception e) { e.printStackTrace(); } }
Let’s just add a statement to pause the program before continuing to the next step. We’ll be adding this after every step so we can see what’s going on throughout the whole program.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file System.out.println("\nLet's upload a file to \"My first folder\"."); String localFile = getLocalFile(); String remoteFolder = getRemoteFolder(smartVault, "My First folder"); smartVault.uploadFile(localFile, remoteFolder); System.out.println("Upload complete"); System.out.println("Press any key to continue"); System.in.read(); . . . } catch (Exception e) { e.printStackTrace(); } }
Creating a Folder
Let’s create a folder in My First Vault. Since our previous method only sends us a path to a folder in the vault, let’s create a method called getRemoteFolder to determine the path to the vault. The method will take in the SmartVault instance.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file System.out.println("\nLet's upload a file to \"My first folder\"."); String localFile = getLocalFile(); String remoteFolder = getRemoteFolder(smartVault, "My First folder"); smartVault.uploadFile(localFile, remoteFolder); System.out.println("Upload complete"); System.out.println("Press any key to continue"); System.in.read(); //Create folder System.out.println("\nLet's create a folder"); String remoteFolder1 = getRemoteFolder(smartVault); . . . } catch (Exception e) { e.printStackTrace(); } }
Let’s implement our new getRemoteFolder. We’ll need to call our browsePath method to retrieve the account name.
private static String getRemoteFolder(SmartVault smartVault) throws Exception { NodeProto.NodeResponse rootNode = smartVault.browsePath("nodes/pth"); String account = rootNode.getMessage().getChildrenList().get(0).getName(); return String.format("/nodes/pth/%s/My First Vault", account); }
Next, ask the user what the new folder should be named. We’ll call this new folder folder_1.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file System.out.println("\nLet's upload a file to \"My first folder\"."); String localFile = getLocalFile(); String remoteFolder = getRemoteFolder(smartVault, "My First folder"); smartVault.uploadFile(localFile, remoteFolder); System.out.println("Upload complete"); System.out.println("Press any key to continue"); System.in.read(); //Create folder System.out.println("\nLet's create a folder"); String remoteFolder1 = getRemoteFolder(smartVault); System.out.println("What do you want to call the folder?"); String folder_1 = keyboard.nextLine(); . . . } catch (Exception e) { e.printStackTrace(); } }
We can now proceed to creating the folder by calling the createFolder method we created earlier. Finally, include the pause before proceeding.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file System.out.println("\nLet's upload a file to \"My first folder\"."); String localFile = getLocalFile(); String remoteFolder = getRemoteFolder(smartVault, "My First folder"); smartVault.uploadFile(localFile, remoteFolder); System.out.println("Upload complete"); System.out.println("Press any key to continue"); System.in.read(); //Create folder System.out.println("\nLet's create a folder"); String remoteFolder1 = getRemoteFolder(smartVault); System.out.println("What do you want to call the folder?"); String folder_1 = keyboard.nextLine(); smartVault.createFolder(remoteFolder1, folder_1); System.out.println(String.format("%s has been created.", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); . . . } catch (Exception e) { e.printStackTrace(); } }
Moving a File
For this tutorial, we will be moving the file we uploaded to folder_1. Before you can move a file to a folder, you’ll need two pieces of information, the location of where the file is and the path of where you would like the file to be located. First, we’ll need to get the location of the file in SmartVault. To do this, let’s create a method called getRemoteFile which takes in the path of the folder the file it is in and the name of the file.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file . . . //Create folder . . . //Move file to folder_1 System.out.println(String.format("Let's move the file into %s.", folder_1)); String remoteFile = getRemoteFile(remoteFolder, Paths.get(localFile).getFileName().toString()); . . . } catch (Exception e) { e.printStackTrace(); } }
Let’s implement getRemoteFile. We’ll simply concatenate the path to the folder and the name of the file.
private static String getRemoteFile(String remoteFolder, String fileName) { return String.format("%s/%s", remoteFolder, fileName); }
Now we just need the new path of the file. To do this, let’s first get the path of the path of the folder where you would like to move the file. Now we can just call getRemoteFile and pass the path to the folder and the name of the file.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file . . . //Create folder . . . //Move file to folder_1 System.out.println(String.format("Let's move the file into %s.", folder_1)); String remoteFile = getRemoteFile(remoteFolder, Paths.get(localFile).getFileName().toString()); remoteFolder1 = getRemoteFolder(smartVault, folder_1); String newRemoteFile = getRemoteFile(remoteFolder1, Paths.get(localFile).getFileName().toString()); . . . } catch (Exception e) { e.printStackTrace(); } }
Lastly, we can actually move the file by calling moveFolder.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file . . . //Create folder . . . //Move file to folder_1 System.out.println(String.format("Let's move the file into %s.", folder_1)); remoteFolder1 = getRemoteFolder(smartVault, folder_1); String remoteFile = getRemoteFile(remoteFolder, Paths.get(localFile).getFileName().toString()); String newRemoteFile = getRemoteFile(remoteFolder1, Paths.get(localFile).getFileName().toString()); smartVault.moveFile(remoteFile, newRemoteFile); System.out.println(String.format("%s has been moved to %s", Paths.get(remoteFile).getFileName().toString(), folder_1)); System.out.println("Press any key to continue.."); System.in.read(); . . . } catch (Exception e) { e.printStackTrace(); } }
Making a Copy of a Folder
We’re going to be making a copy of folder_1. Let’s first ask the user what they want to name the copy. Save it as folder_2.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file . . . //Create folder . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) System.out.println(String.format("Let's make a copy of %s", folder_1)); System.out.println("What would you like to name the copy?"); String folder_2 = keyboard.nextLine(); . . . } catch (Exception e) { e.printStackTrace(); } }
To get the path of the copy, let’s call getRemoteFolder and pass the SmartVault instance and folder_2.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file . . . //Create folder . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) System.out.println(String.format("Let's make a copy of %s", folder_1)); System.out.println("What would you like to name the copy?"); String folder_2 = keyboard.nextLine(); String remoteFolder2 = getRemoteFolder(smartVault, folder_2); . . . } catch (Exception e) { e.printStackTrace(); } }
Now let’s call our copy method in order to actually copy the folder in the specified location.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file . . . //Create folder . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) System.out.println(String.format("Let's make a copy of %s", folder_1)); System.out.println("What would you like to name the copy?"); String folder_2 = keyboard.nextLine(); String remoteFolder2 = getRemoteFolder(smartVault, folder_2); smartVault.copy(remoteFolder1, remoteFolder2); System.out.println(String.format("%s has been copied", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); } catch (Exception e) { e.printStackTrace(); } }
Moving a Folder
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file . . . //Create folder . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 System.out.println(String.format("Let's move %s inside %s", folder_2, folder_1)); smartVault.moveFolder(remoteFolder2, remoteFolder1); System.out.println(String.format("%s has been moved inside %s", folder_2, folder_1)); System.out.println("Press any key to continue.."); System.in.read(); } catch (Exception e) { e.printStackTrace(); } }
Modifying Folder Properties
For this tutorial, we will modify the description of folder_1. Before we can change the description of a folder, we’ll need to ask the user for the updated description.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties System.out.println(String.format("Let's modify the description of %s", folder_1)); System.out.println("What would you like to change the description of the folder to?"); String folderDescription = keyboard.nextLine(); . . . } catch (Exception e) { e.printStackTrace(); } }
Now, let’s just call the ModifyFolder method to change the description of folder_1.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties System.out.println(String.format("Let's modify the description of %s", folder_1)); System.out.println("What would you like to change the description of the folder to?"); String folderDescription = keyboard.nextLine(); smartVault.modifyFolder(remoteFolder1, folderDescription); System.out.println(String.format("The description of %s has been updated", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); } catch (Exception e) { e.printStackTrace(); } }
Modifying File Properties
Next, let’s modify the description of the file inside folder_1. We’ll need to ask the user for description once more.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties System.out.println(String.format("Let's modify the description of %s", Paths.get(localFile).getFileName().toString())); System.out.println("What would you like to change the description of the file to?"); String fileDescription = keyboard.nextLine(); . . . } catch (Exception e) { e.printStackTrace(); } }
Finally, call ModifyFile to update the description.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties System.out.println(String.format("Let's modify the description of %s", Paths.get(localFile).getFileName().toString())); System.out.println("What would you like to change the description of the file to?"); String fileDescription = keyboard.nextLine(); smartVault.modifyFile(newRemoteFile, fileDescription); System.out.println(String.format("The description of %s has been updated", Paths.get(newRemoteFile).getFileName().toString())); System.out.println("Press any key to continue.."); System.in.read(); } catch (Exception e) { e.printStackTrace(); } }
Deleting a File
Let’s delete the file we uploaded earlier. (We still have the path of this file saved under newRemoteFile). Call the DeleteFile method and send the path of the file to be removed.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties . . . //Delete file System.out.println(String.format("Let's delete %s", Paths.get(newRemoteFile).getFileName().toString())); smartVault.deleteFile(newRemoteFile); System.out.println(String.format("%s has been deleted", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); } catch (Exception e) { e.printStackTrace(); } }
Finally, let’s delete folder_1. Simply call the deleteFolder method and send the path of the folder.
Deleting a folder
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties . . . //Delete file . . . //Delete folder System.out.println(String.format("Let's make a copy of %s", Paths.get(newRemoteFile).getFileName().toString())); smartVault.deleteFolder(remoteFolder1); System.out.println(String.format("%s has been deleted", folder_1)); } catch (Exception e) { e.printStackTrace(); } }
Finishing It Up
Let’s go ahead and add a prompt to have the user press the enter key to exit to prevent the console application from quitting so we can see the of end of the program’s output.
public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties . . . //Delete file . . . //Delete folder . . . } catch (Exception e) { e.printStackTrace(); } System.out.println("\nPress 'Enter' key to exit"); keyboard.nextLine(); }
Putting It Together
SmartVault.java
import com.smartvault.net.ClientNetContext; import com.smartvault.net.WebRequestInfo; import com.smartvault.proto.*; import com.smartvault.rest.*; import com.sun.corba.se.spi.activation.Server; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.openssl.PEMReader; import java.io.FileInputStream; import java.io.StringReader; import java.nio.file.Paths; import java.security.KeyPair; import java.security.Security; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.openssl.PEMReader; public class SmartVault { private ClientProtocol _protocol; private DelegatedProtocol _delegation; public SmartVault() throws Exception { // Change this to your client ID String clientId = "JavaTutorial"; // Change this to your private key String privateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" + "MIIEogIBAAKCAQEA0+UlqixNqRoNrZhRj90MP14SavZkMPxFhJEN0p23fxIlOIY0\r\n" + "4SW3IO5iyT5PUsOtK6Gigp2zn3uEMqAVI2MwR9fXBI7iVuOThIDTt+DygBHHWc52\r\n" + "6Fcd5aU8lxtg02SGJ5HZgKWI/8pHfQbd+pFPrEF50saVb/XPfN74OWx5pWsJbQz9\r\n" + "B8XodDswGzKmyqVeicPefSIn9qa2AkbLNhANbEgx+VE1p+L1X3r3z4sZ/Cks/5nr\r\n" + "2fO5AayhNzwTbN71s82M2Q5WgvxbM+ahSPHvtkgwzi9+XiEyOkUnkoftBSoxPZB1\r\n" + "GWYriEwCsp+iQljehKl/ugYbqBMn1kaqOP8xJQIDAQABAoIBAF4gFDMbqwPLBvhu\r\n" + "CQ0W7DHZ3+STvr3j0h2pMbK1TKWtscsCEstQraB7RHaQrzvcoDgZfM74rqnRfE/g\r\n" + "vIMTtIa1YlYsAm8GeKkLcQDlc9NgEmXaSQe8axNv6xJUnxZIOS+qoit7XPgDKu5m\r\n" + "9oQvuGyUSUFP5WHul1So1yrq/L51lp9rhRJLnKPjTlFsTLXjoh2StrmS3LHfvn3Y\r\n" + "3l/Ftk6mv+0Z0KXXIxCQR+Hn9193rwrOJ4NlgOPeeNjadhSRrZNdwoXw9Y55R9hw\r\n" + "3WxHHZPHeQi6K1kDm2UT8qG078p9d11QrzE6xBPMVP5s8GxJ5H+QfT7jLBJJ8w2F\r\n" + "w3NmyQECgYEA7+2V5OmJ2RBal8o/VIq/wwMn1YMqR4Tz5V2bFlV+HHVqF/SVDf8Q\r\n" + "nIs7/hsVeWGu2XWgLbL7TWngjkSjEx3prhbeuMLrOjpPlE8zTopUP8qkzHSAFYgw\r\n" + "NA5XaRxc55Guo9gRQQKj9/o9iTRoZZEuwA7oIguOVvEcGH9axJNFs4kCgYEA4hbW\r\n" + "YKrJMIdnb0Lbj0sUUbgXvbxUHpdL0iRKGGpZC7qauEUWyML+TqGQt47A9bsOxpuo\r\n" + "ZiHKcdeJ+Y6+S6klzTtUXFHnNnVtVj/d1TJe2WaiXWJPWOip1MzkmeaW7GlyZAG9\r\n" + "2ERB1pDv76e0ZefgLN5kCnbRb/dsEtyTz8IyPb0CgYA6ULvjFKRNnvz18dFswgCT\r\n" + "7Jts+OF42qbRM+wzBHqPfjZYNjlYWot2ER12yKxygTyXXFCfauZLzZUn3yTny5h1\r\n" + "mNdvfujfkTawbIOi7lpF2wItM4/CLATTUj0KrjsiibUx251t+K9T4X29cICDV0NO\r\n" + "qRDg3YAuP5I9ng64wrbpSQKBgEb9aL7doWKNgZrb4Vjy+CRYq4u18KvSUcpf/qv/\r\n" + "6InYQ/CMMQVExNknvesE9e2ymIcgJRY8kfaA+R/VBEd5ixcQBAMg7HqbEIO+dgcV\r\n" + "U9brdRvhXIzMMVdSJo10a/s7eOGR8mxPsmSPCee0Pt6omik8gykN+eEwTUz22aqo\r\n" + "jWH5AoGAYWd+y1wcI4ZkqdnoGbFapo2BjeZmFEV5KUhXWW7eJCmh6iD6hWr5b1ZR\r\n" + "6aQQyUNITq40JvIkTpgNO7bJ49+yL0SbCQXiJLoH2nvLK7sGLYOq0GQxD2sn3eLW\r\n" + "/qKTFd4LAK6dCMklQzr1Ev9cWMFm0DLUdOnKNv6zvme67Gs9xPE=\r\n" + "-----END RSA PRIVATE KEY-----\r\n"; Security.addProvider(new BouncyCastleProvider()); StringReader reader = new StringReader(privateKey); KeyPair keyPair = (KeyPair) new PEMReader(reader).readObject(); ServerCfg cfg = new ServerCfg("https://rest.smartvault.com", clientId, keyPair.getPrivate()); Authentication auth = new Authentication(cfg); _protocol = auth.createClientProtocol(); } public String requestAuthorization(String email) throws Exception { BasicUserInfoProto.BasicUserInfoResponse response = _protocol.statUser(email); return response.getMessage().getAuthorizationUri(); } public void authenticate(String email) throws Exception { _delegation = _protocol.createDelegatedProtocol(email); } public NodeProto.NodeResponse browsePath(String path) throws Exception { int children = 1; // Immediate contents only return _delegation.navigate(path, children); } public void uploadFile(String localFile, String remoteFolder) throws Exception { FileInputStream stream = new FileInputStream(localFile); UploadFileProto.UploadFileRequest.Builder builder = UploadFileProto.UploadFileRequest.newBuilder(); builder.setName(Paths.get(localFile).getFileName().toString()); _delegation.postFile(remoteFolder, builder.build(), stream); stream.close(); } public void createFolder(String destination, String name) throws Exception { _delegation.createFolder(destination, name); } public void moveFile(String fileToMove, String remoteFolder) throws Exception { _delegation.move(fileToMove, remoteFolder); } public void moveFolder(String folderToMove, String remoteFolder) throws Exception { String newPath = String.format("%s/%s", remoteFolder, Paths.get(folderToMove).getFileName().toString()); _delegation.move(folderToMove, newPath); } public void copy(String ToCopy, String remoteFolder) throws Exception { _delegation.copy(ToCopy, remoteFolder); } public void modifyFile(String remoteFile, String description) throws Exception { _delegation.modifyFile(remoteFile, description); } public void modifyFolder(String remoteFolder, String description) throws Exception { _delegation.modifyFolder(remoteFolder, description); } public void deleteFile(String remoteFile) throws Exception { _delegation.deleteFile(remoteFile); } public void deleteFolder(String remoteFolder) throws Exception { _delegation.deleteFile(remoteFolder); } }
Program.java
import com.smartvault.proto.NodeProto; import java.awt.*; import java.net.URI; import java.nio.file.Paths; import java.util.Scanner; public class Program { private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { try { SmartVault smartVault = new SmartVault(); authenticate(smartVault); //Upload file System.out.println("\nLet's upload a file to \"My first folder\"."); String localFile = getLocalFile(); String remoteFolder = getRemoteFolder(smartVault, "My First folder"); smartVault.uploadFile(localFile, remoteFolder); System.out.println("Upload complete."); System.out.println("Press any key to continue.."); System.in.read(); //Create folder System.out.println("\nLet's create a folder"); String remoteFolder1 = getRemoteFolder(smartVault); System.out.println("What do you want to call the folder?"); String folder_1 = keyboard.nextLine(); smartVault.createFolder(remoteFolder1, folder_1); System.out.println(String.format("%s has been created.", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); //Move file to folder_1 System.out.println(String.format("Let's move the file into %s.", folder_1)); String remoteFile = getRemoteFile(remoteFolder, Paths.get(localFile).getFileName().toString()); remoteFolder1 = getRemoteFolder(smartVault, folder_1); String newRemoteFile = getRemoteFile(remoteFolder1, Paths.get(localFile).getFileName().toString()); smartVault.moveFile(remoteFile, newRemoteFile); System.out.println(String.format("%s has been moved to %s", Paths.get(remoteFile).getFileName().toString(), folder_1)); System.out.println("Press any key to continue.."); System.in.read(); //Make a copy of folder_1 (folder_2) System.out.println(String.format("Let's make a copy of %s", folder_1)); System.out.println("What would you like to name the copy?"); String folder_2 = keyboard.nextLine(); String remoteFolder2 = getRemoteFolder(smartVault, folder_2); smartVault.copy(remoteFolder1, remoteFolder2); System.out.println(String.format("%s has been copied", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); //Move folder_2 inside folder_1 System.out.println(String.format("Let's move %s inside %s", folder_2, folder_1)); System.out.println(String.format("remoteFolder1: %s", remoteFolder1)); System.out.println(String.format("remoteFolder2: %s", remoteFolder2)); System.out.println(String.format("%s has been moved inside %s", folder_2, folder_1)); System.out.println("Press any key to continue.."); System.in.read(); //Modify folder_1 properties System.out.println(String.format("Let's modify the description of %s", folder_1)); System.out.println("What would you like to change the description of the folder to?"); String folderDescription = keyboard.nextLine(); smartVault.modifyFolder(remoteFolder1, folderDescription); System.out.println(String.format("The description of %s has been updated", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); //Modify file properties System.out.println(String.format("Let's modify the description of %s", Paths.get(localFile).getFileName().toString())); System.out.println("What would you like to change the description of the file to?"); String fileDescription = keyboard.nextLine(); smartVault.modifyFile(newRemoteFile, fileDescription); System.out.println(String.format("The description of %s has been updated", Paths.get(newRemoteFile).getFileName().toString())); System.out.println("Press any key to continue.."); System.in.read(); //Delete file System.out.println(String.format("Let's delete %s", Paths.get(newRemoteFile).getFileName().toString())); smartVault.deleteFile(newRemoteFile); System.out.println(String.format("%s has been deleted", folder_1)); System.out.println("Press any key to continue.."); System.in.read(); //Delete folder System.out.println(String.format("Let's make a copy of %s", Paths.get(newRemoteFile).getFileName().toString())); smartVault.deleteFolder(remoteFolder1); System.out.println(String.format("%s has been deleted", folder_1)); } catch (Exception e) { e.printStackTrace(); } System.out.println("\nPress 'Enter' key to exit"); keyboard.nextLine(); } private static void authenticate(SmartVault smartVault) throws Exception { // Autonomous authentication System.out.print("Enter your email address: "); String email = keyboard.nextLine(); System.out.print("Have you authorized this application? [y/n]: "); String response = keyboard.nextLine(); if (!response.toLowerCase().startsWith("y")) { String url = smartVault.requestAuthorization(email); Desktop.getDesktop().browse(URI.create(url)); System.out.println("\nPress 'Enter' once you have allowed this application."); keyboard.nextLine(); } smartVault.authenticate(email); } private static String getLocalFile() { System.out.println("Enter the path to a file to upload. " + "(Hint: drag a file to the console window): "); String localFile = keyboard.nextLine(); return localFile.replace("\"", ""); // Remove quotes, if supplied } private static String getRemoteFile(String remoteFolder, String fileName) { return String.format("%s/%s", remoteFolder, fileName); } private static String getRemoteFolder(SmartVault smartVault, String folderName) throws Exception { NodeProto.NodeResponse rootNode = smartVault.browsePath("nodes/pth"); String account = rootNode.getMessage().getChildrenList().get(0).getName(); return String.format("/nodes/pth/%s/My First Vault/%s", account, folderName); } private static String getRemoteFolder(SmartVault smartVault) throws Exception { NodeProto.NodeResponse rootNode = smartVault.browsePath("nodes/pth"); String account = rootNode.getMessage().getChildrenList().get(0).getName(); return String.format("/nodes/pth/%s/My First Vault", account); } }
Here’s What You’ll Need
To perform autonomous authentication, we will first need to generate a RSA key pair. Visit Generating a Key Pair to view the steps on how to create them.
If you have not yet created a developer account or client ID, visit Creating a Developer Account to view the steps on how to create them.
Setting Up
You will also need to install the C# API wrapper library, begin communicating with SmartVault, and create a method to handle autonomous authentication. The following tutorial will guide you through this process:
Autonomous Authentication
Browsing the Folder Structure
A very common task in SmartVault is browsing the folder structure. For generic integrations, this is done using the /nodes/pth structure. The root of this structure contains the user’s accounts. Accounts contain vaults, and vaults contain folders. Folders are where files are typically stored.
Let’s create a method called browsePath to implement browsing this structure in a simplified way. This method will take in a path to browse and output the response. The variable children controls how deep in the structure we want to traverse on each call. Setting this to 1 will make the response contain the immediate contents of the path retrieved.
public NodeResponse BrowsePath(string path) { int children = 1; // Immediate contents only return _delegation.Navigate(new AbsolutePath(path), children); }
Uploading Files
Let’s create a method called UploadFile to handle uploading files from the local computer to SmartVault. This method can take in a string containing the path to the file on the local machine, and the path to folder in SmartVault where we want to store it.
public void UploadFile(string localFile, string remoteFolder) { ... }
The first step with uploading a file is creating a Stream pointing to the file on the local computer. This stream will be read by the library and used to transmit the file’s data to SmartVault.
public void UploadFile(string localFile, string remoteFolder) { Console.WriteLine("Uploading '{0}' to '{1}'...", Path.GetFileName(localFile), Path.GetFileName(remoteFolder)); FileStream stream = new FileStream(localFile, FileMode.Open); . . . }
Now we need to build an UploadFileRequest in order to upload the file. This contains the file’s metadata, including the file name in SmartVault. For this example, we will use the same filename as used for the original file on the local computer.
public void UploadFile(string localFile, string remoteFolder) { Console.WriteLine("Uploading '{0}' to '{1}'...", Path.GetFileName(localFile), Path.GetFileName(remoteFolder)); FileStream stream = new FileStream(localFile, FileMode.Open); UploadFileRequest.Builder builder = UploadFileRequest.CreateBuilder(); builder.Name = Path.GetFileName(localFile); . . . }
Next, we need to actually upload the file, using a library call that takes in the request, the folder path to store it in, and the stream pointing to the file data.
public void UploadFile(string localFile, string remoteFolder) { Console.WriteLine("Uploading '{0}' to '{1}'...", Path.GetFileName(localFile), Path.GetFileName(remoteFolder)); FileStream stream = new FileStream(localFile, FileMode.Open); UploadFileRequest.Builder builder = UploadFileRequest.CreateBuilder(); builder.Name = Path.GetFileName(localFile); _delegation.PostFile(new AbsolutePath(remoteFolder), builder.Build(), stream); . . . }
Finally, we’re going to want to close that stream.
public void UploadFile(string localFile, string remoteFolder) { Console.WriteLine("Uploading '{0}' to '{1}'...", Path.GetFileName(localFile), Path.GetFileName(remoteFolder)); FileStream stream = new FileStream(localFile, FileMode.Open); UploadFileRequest.Builder builder = UploadFileRequest.CreateBuilder(); builder.Name = Path.GetFileName(localFile); _delegation.PostFile(new AbsolutePath(remoteFolder), builder.Build(), stream); stream.Close(); }
Creating Folders
Now we’ll create a method called createFolder to handle the creation of folders. This method will take in a the path in SmartVault where you want the folder to be located and the name that you want to give to the folder.
public void CreateFolder(string newFolder) { . . . }
All we need to do here is build a CreateFolderRequest and then use a library call to create the folder that takes in the destination path and the name of the new folder.
public void CreateFolder(string newFolder) { Console.WriteLine("Creating '{0}' folder...", Path.GetFileName(newFolder)); CreateFolderRequest.Builder builder = CreateFolderRequest.CreateBuilder(); _delegation.CreateFolder(new AbsolutePath(newFolder), builder.Build()); }
Moving a File
Now let’s create another method called moveFile, which will take in the path of the file you want to move and what you want the new path of the file to be.
public void MoveFile(string fileToMove, string remoteFolder) { . . . }
And simply place the library call that moves the folder and takes in the path of the file you want to move and the new file path.
public void MoveFile(string fileToMove, string remoteFolder) { Console.WriteLine("Moving '{0}' to '{1}'...", Path.GetFileName(fileToMove), remoteFolder); _delegation.Move(new AbsolutePath(fileToMove), new AbsolutePath(remoteFolder)); }
Moving a Folder
Next, let’s create a method called moveFolder that takes in the path of the folder you want to move and the location where you want the folder.
public void MoveFolder(string folderToMove, string remoteFolder) { . . . }
Since we need to pass what you want the actual path of the moved folder to be, let’s create a new string called newPath which will hold this new path by concatenating the location where you want to place the folder and the name of the folder you are moving.
public void MoveFolder(string folderToMove, string remoteFolder) { string folderName = Path.GetFileName(folderToMove); remoteFolder += String.Format("/{0}",folderName); . . . }
Finally, let’s make the library call to move the folder, and pass the location of the folder you want to move and the new path of the folder.
public void MoveFolder(string folderToMove, string remoteFolder) { string folderName = Path.GetFileName(folderToMove); remoteFolder += String.Format("/{0}",folderName); Console.WriteLine("Moving '{0}' to '{1}'...", Path.GetFileName(folderToMove), remoteFolder); _delegation.Move(new AbsolutePath(folderToMove), new AbsolutePath(remoteFolder)); }
Making a Copy
Next, we’ll make a method called copyFolder which will take in the path of the file or folder you want to copy, including the name of the folder or file you want to copy.
public void copy(String toCopy, String remoteFolder) throws Exception { . . . }
And let’s just place the library call, which takes in the path of the folder or file you want to copy, and the path of the new one.
public void Copy(string folderToCopy, string remoteFolder) { Console.WriteLine("Copying '{0}'...", Path.GetFileName(folderToCopy)); _delegation.Copy(new AbsolutePath(folderToCopy), new AbsolutePath(remoteFolder)); }
Modifying a Folder’s Properties
Let’s proceed to create a method called modifyFolder which will modify the properties of the folder. For this tutorial, we will be updating the description. The method will take in the path of the folder you want to modify and the new description.
public void ModifyFolder(string remoteFolder, string description) { . . . }
We will need to first build a UpdateNodeRequest called updateBuilder. This will take in the updated description. Next, create a ChangeNodeRequest called changeBuilder. Set the change builder to do an update and set it equal to the updateBuilder.
public void ModifyFolder(string remoteFolder, string description) { Console.WriteLine("Modifying '{0}' description to '{1}'...", Path.GetFileName(remoteFolder), description); UpdateNodeRequest.Builder updateBuilder = UpdateNodeRequest.CreateBuilder(); updateBuilder.Description = description; ChangeNodeRequest.Builder changeBuilder = ChangeNodeRequest.CreateBuilder(); changeBuilder.Update = updateBuilder.Build(); . . . }
Now make the library call, which takes in the path and the changeBuilder.
public void ModifyFolder(string remoteFolder, string description) { Console.WriteLine("Modifying '{0}' description to '{1}'...", Path.GetFileName(remoteFolder), description); UpdateNodeRequest.Builder updateBuilder = UpdateNodeRequest.CreateBuilder(); updateBuilder.Description = description; ChangeNodeRequest.Builder changeBuilder = ChangeNodeRequest.CreateBuilder(); changeBuilder.Update = updateBuilder.Build(); _delegation.Update(new AbsolutePath(remoteFolder), new NodeOptions(), changeBuilder.Build()); }
Modifying a File’s Properties
Create a method called modifyFile, which will take in the path of the file whose properties you would like to update and the new description you would like to give it.
public void ModifyFile(string remoteFile, string description) { . . . }
We will need to first build a UpdateNodeRequest called updateBuilder. Using updateBuilder, set UpdateDescription to true and set the Description to the updated description. Next, create a ChangeNodeRequest called changeBuilder. Set the change builder to do an update and set it equal to the updateBuilder.
public void ModifyFile(string remoteFile, string description) { Console.WriteLine("Modifying '{0}' description to '{1}'...", Path.GetFileName(remoteFile), description); UpdateNodeRequest.Builder updateBuilder = UpdateNodeRequest.CreateBuilder(); updateBuilder.Description = description; updateBuilder.UpdateDescription = true; ChangeNodeRequest.Builder changeBuilder = ChangeNodeRequest.CreateBuilder(); changeBuilder.Update = updateBuilder.Build(); . . . }
Now make the library call, which takes in the path and the changeBuilder.
public void ModifyFile(string remoteFile, string description) { Console.WriteLine("Modifying '{0}' description to '{1}'...", Path.GetFileName(remoteFile), description); UpdateNodeRequest.Builder updateBuilder = UpdateNodeRequest.CreateBuilder(); updateBuilder.Description = description; updateBuilder.UpdateDescription = true; ChangeNodeRequest.Builder changeBuilder = ChangeNodeRequest.CreateBuilder(); changeBuilder.Update = updateBuilder.Build(); _delegation.Update(new AbsolutePath(remoteFile), new NodeOptions(), changeBuilder.Build()); }
Deleting a File
Create a new method called deleteFile with one parameter, the path of the file you would like to remove.
public void DeleteFile(string remoteFile) { . . . }
Now simply make the library call to delete the file and pass the path of the file.
public void DeleteFile(string remoteFile) { Console.WriteLine("Deleting '{0}'...", Path.GetFileName(remoteFile)); _delegation.DeleteFile(new AbsolutePath(remoteFile)); }
Deleting a Folder
Lastly, let’s make a method called deleteFolder which will take in the path of the folder.
public void DeleteFolder(string remoteFolder) { . . . }
And simply make the library call to delete the file and send the path of the file that you want to remove.
public void DeleteFolder(string remoteFolder) { Console.WriteLine("Deleting '{0}'...", Path.GetFileName(remoteFolder)); _delegation.DeleteFile(new AbsolutePath(remoteFolder)); }
Trying It Out
Setting Up
Now that we’ve got a nice wrapper class to handle some basic operations, let’s try it out! We’re going to make a simple console program that uploads a file to SmartVault and downloads it again.
Let’s start with a simple Main method.
public static void Main(String[] args) { ... }
Opening the Connection
All we need to do is create an instance of our SmartVault class to open a connection.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); . . . }
Authenticating
Include the Authenticate method you created using the Autonomous Authentication tutorial.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); . . . }
Uploading a File
Before we can upload a file, we need two pieces of information: the path to the file on the local system and the path in SmartVault where the file needs to be stored. Let’s call a new method called GetLocalFile to get the local file path from the user.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file Console.WriteLine("\nLet's upload a file to \"My First folder\"."); string localFile = GetLocalFile(); . . . }
Now let’s implement the GetLocalFile method. This will ask the user to input a file from the console.
private static string GetLocalFile() { Console.WriteLine("Enter the path to a file to upload. " + "(Hint: drag a file to the console window): "); string localFile = Console.ReadLine(); return localFile.Replace("\"", ""); // Remove quotes, if supplied }
Let’s go back to our Main method and call a new method called GetRemoteFolder to determine where to store the file in SmartVault. This method will take in the SmartVault instance we just created and the name of the folder you want to get the path of. For this tutorial, let’s assume that we’re going to upload the file to My First folder. If you have changed the name of this vault or folder in your account, you’ll probably want to update them here to match.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file Console.WriteLine("\nLet's upload a file to \"My First folder\"."); string localFile = GetLocalFile(); string remoteFolder = GetRemoteFolder(smartVault, "My First folder"); . . . }
Now let’s implement GetRemoteFolder. SmartVault automatically creates an account for the user on signup containing a vault called My First Vault and a folder called My First folder.
This still doesn’t give us the account name, which is randomly generated on signup. But we can use our browsePath method to retrieve it.
private static string GetRemoteFolder(SmartVault smartVault, string folderName) { var rootNode = smartVault.BrowsePath("/nodes/pth"); string account = rootNode.Message.ChildrenList[0].Name; return String.Format("/nodes/pth/{0}/My First Vault/{1}", account, folderName); }
Finally, we can actually upload the file using the UploadFile method we created earlier. Let’s do this in the Main method.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file Console.WriteLine("\nLet's upload a file to \"My First folder\"."); string localFile = GetLocalFile(); string remoteFolder = GetRemoteFolder(smartVault, "My First folder"); smartVault.UploadFile(localFile, remoteFolder); Console.WriteLine("Upload complete"); . . . }
Let’s just add a statement to pause the program before continuing to the next step. We’ll be adding this after every step so we can see what’s going on throughout the whole program.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file Console.WriteLine("\nLet's upload a file to \"My First folder\"."); string localFile = GetLocalFile(); string remoteFolder = GetRemoteFolder(smartVault, "My First folder"); smartVault.UploadFile(localFile, remoteFolder); Console.WriteLine("Upload complete"); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); . . . }
Creating a Folder
Ask the user what they would like to name the new folder—let’s call it folder_1
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) Console.WriteLine("\nLet's create a folder."); Console.WriteLine("What do you want to call the folder?"); string folder_1 = Console.ReadLine(); . . . }
We’re going to create the folder in My First Vault. Since our previous method only sends us a path to a folder in the vault, let’s create a method call GetRemoteFolder to determine the path to the new folder.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) Console.WriteLine("\nLet's create a folder."); Console.WriteLine("What do you want to call the folder?"); string folder_1 = Console.ReadLine(); string remoteFolder1 = GetRemoteFolder(smartVault, folder_1); . . . }
We can now proceed to creating the folder by calling the CreateFolder method we created earlier. Finally, include the pause before proceeding.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) Console.WriteLine("\nLet's create a folder."); Console.WriteLine("What do you want to call the folder?"); string folder_1 = Console.ReadLine(); string remoteFolder1 = GetRemoteFolder(smartVault, folder_1); smartVault.CreateFolder(remoteFolder1); Console.WriteLine("'{0}' has been created.", folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); . . . }
Moving a File
For this tutorial, we will be moving the file we uploaded to folder_1. Before you can move a file to a folder, you’ll need two pieces of information—the location of where the file is and path of where you would like the file to be located. First, we’ll need to get the location of the file in SmartVault. To do this, let’s create a method called GetRemoteFile which takes in the path of the folder the file is in and the name of the file.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 Console.WriteLine("\nLet's move the file into '{0}'.", folder_1); string remoteFile = GetRemoteFile(remoteFolder, Path.GetFileName(localFile)); . . . }
Let’s implement GetRemoteFile. We’ll simply concatenate the path to the folder and the name of the file.
private static string GetRemoteFile(string remoteFolder, string fileName) { return String.Format("{0}/{1}", remoteFolder, fileName); }
Now we just need the new path of the file. To do this, let’s first get the path of the folder where you would like to move the file. Now we can just call GetRemoteFile and pass the path to the folder and the name of the file.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 Console.WriteLine("\nLet's move the file into '{0}'.", folder_1); string remoteFile = GetRemoteFile(remoteFolder, Path.GetFileName(localFile)); string newRemoteFile = GetRemoteFile(remoteFolder1, Path.GetFileName(localFile)); . . . }
Lastly, we can actually move the file by calling MoveFolder.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 Console.WriteLine("\nLet's move the file into '{0}'.", folder_1); string remoteFile = GetRemoteFile(remoteFolder, Path.GetFileName(localFile)); string newRemoteFile = GetRemoteFile(remoteFolder1, Path.GetFileName(localFile)); smartVault.MoveFile(remoteFile, newRemoteFile); Console.WriteLine("'{0}' has been moved to '{1}'", Path.GetFileName(remoteFile), folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); . . . }
Making a Copy of a Folder
We’re going to be making a copy of folder_1. Let’s first ask the user what they want to name the copy. Save it as folder_2.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) Console.WriteLine("\nLet's make a copy of {0}.", folder_1); Console.WriteLine("What would you like to name the copy?"); string folder_2 = Console.ReadLine(); . . . }
To get the path of the copy, let’s call GetRemoteFolder and pass the SmartVault instance and folder_2.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) Console.WriteLine("\nLet's make a copy of {0}.", folder_1); Console.WriteLine("What would you like to name the copy?"); string folder_2 = Console.ReadLine(); string remoteFolder2 = GetRemoteFolder(smartVault, folder_2); . . . }
Now let’s call our Copy method in order to actually copy the folder in the specified location.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) Console.WriteLine("\nLet's make a copy of {0}.", folder_1); Console.WriteLine("What would you like to name the copy?"); string folder_2 = Console.ReadLine(); string remoteFolder2 = GetRemoteFolder(smartVault, folder_2); smartVault.Copy(remoteFolder1, remoteFolder2); Console.WriteLine("'{0}' has been copied", folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); }
Moving a Folder
Let’s move folder_2 inside of folder_1. Since we already have the paths of these two folders, all we need to do is call the MoveFolder method and send both paths.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 Console.WriteLine("\nLet's move '{0}' inside '{1}'.", folder_2, folder_1); smartVault.MoveFolder(remoteFolder2, remoteFolder1); Console.WriteLine("'{0}' has been moved inside '{1}'.", folder_2, folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); }
Modifying Folder Properties
For this tutorial, we will modify the description of folder_1. Before we can change the description of a folder, we’ll need to ask the user for the updated description.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties Console.WriteLine("\nLet's modify the description of '{0}'.", folder_1); Console.WriteLine("What would you like to update the description of the folder to?"); string folderDescription = Console.ReadLine(); . . . }
Now, let’s just call the ModifyFolder method to change the description of folder_1.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties Console.WriteLine("\nLet's modify the description of '{0}'.", folder_1); Console.WriteLine("What would you like to update the description of the folder to?"); string folderDescription = Console.ReadLine(); smartVault.ModifyFolder(remoteFolder1, folderDescription); Console.WriteLine("The description of '{0}' has been updated.", Path.GetFileName(remoteFolder1)); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); }
Modifying File Properties
Next, let’s modify the description of the file inside folder_1. We’ll need to ask the user for description once more.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties Console.WriteLine("\nLet's modify the description of '{0}'.", Path.GetFileName(localFile)); Console.WriteLine("What would you like to update the description of the file to?"); string fileDescription = Console.ReadLine(); . . . }
Finally, call ModifyFile to update the description.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties Console.WriteLine("\nLet's modify the description of '{0}'.", Path.GetFileName(localFile)); Console.WriteLine("What would you like to update the description of the file to?"); string fileDescription = Console.ReadLine(); smartVault.ModifyFile(newRemoteFile, fileDescription); Console.WriteLine("The description of '{0}' has been updated.", Path.GetFileName(newRemoteFile)); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); }
Deleting a File
Let’s delete the file we uploaded earlier. (We still have the path of this file saved under newRemoteFile). Call the DeleteFile method and send the path of the file to be removed.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties . . . //Delete file Console.WriteLine("\nLet's delete '{0}'", Path.GetFileName(newRemoteFile)); smartVault.DeleteFile(newRemoteFile); Console.WriteLine("'{0}' has been deleted.", Path.GetFileName(newRemoteFile)); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); }
Finally, let’s delete folder_1. Simply call the DeleteFolder method and send the path of the folder.
Deleting a Folder
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties . . . //Delete file . . . //Delete folder Console.WriteLine("\nLet's delete '{0}'", Path.GetFileName(remoteFolder1)); smartVault.DeleteFolder(remoteFolder1); Console.WriteLine("'{0}' has been deleted.", Path.GetFileName(remoteFolder1)); }
Finishing It Up
Let’s go ahead and add a prompt to have the user press the enter key to exit to prevent the console application from quitting so we can see the of end of the program’s output.
static void Main(string[] args) { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file . . . //Create folder (folder_1) . . . //Move file to folder_1 . . . //Make a copy of folder_1 (folder_2) . . . //Move folder_2 inside folder_1 . . . //Modify folder_1 properties . . . //Modify file properties . . . //Delete file . . . //Delete folder . . . Console.WriteLine("\nPress any key to exit"); Console.ReadKey(); }
Putting It Together
SmartVault.cs
using System; using SmartVault.Core; using SmartVault.Proto; using SmartVault.Rest; using System.IO; using System.Linq; namespace HelloWorldSVRest { class SmartVault { private ClientProtocol _protocol; private DelegatedProtocol _delegation; public SmartVault() { // Change this to your client ID string clientId = "CSharpTutorial"; //Change this to your public key string privateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" + "MIIEogIBAAKCAQEA0+UlqixNqRoNrZhRj90MP14SavZkMPxFhJEN0p23fxIlOIY0\r\n" + "4SW3IO5iyT5PUsOtK6Gigp2zn3uEMqAVI2MwR9fXBI7iVuOThIDTt+DygBHHWc52\r\n" + "6Fcd5aU8lxtg02SGJ5HZgKWI/8pHfQbd+pFPrEF50saVb/XPfN74OWx5pWsJbQz9\r\n" + "B8XodDswGzKmyqVeicPefSIn9qa2AkbLNhANbEgx+VE1p+L1X3r3z4sZ/Cks/5nr\r\n" + "2fO5AayhNzwTbN71s82M2Q5WgvxbM+ahSPHvtkgwzi9+XiEyOkUnkoftBSoxPZB1\r\n" + "GWYriEwCsp+iQljehKl/ugYbqBMn1kaqOP8xJQIDAQABAoIBAF4gFDMbqwPLBvhu\r\n" + "CQ0W7DHZ3+STvr3j0h2pMbK1TKWtscsCEstQraB7RHaQrzvcoDgZfM74rqnRfE/g\r\n" + "vIMTtIa1YlYsAm8GeKkLcQDlc9NgEmXaSQe8axNv6xJUnxZIOS+qoit7XPgDKu5m\r\n" + "9oQvuGyUSUFP5WHul1So1yrq/L51lp9rhRJLnKPjTlFsTLXjoh2StrmS3LHfvn3Y\r\n" + "3l/Ftk6mv+0Z0KXXIxCQR+Hn9193rwrOJ4NlgOPeeNjadhSRrZNdwoXw9Y55R9hw\r\n" + "3WxHHZPHeQi6K1kDm2UT8qG078p9d11QrzE6xBPMVP5s8GxJ5H+QfT7jLBJJ8w2F\r\n" + "w3NmyQECgYEA7+2V5OmJ2RBal8o/VIq/wwMn1YMqR4Tz5V2bFlV+HHVqF/SVDf8Q\r\n" + "nIs7/hsVeWGu2XWgLbL7TWngjkSjEx3prhbeuMLrOjpPlE8zTopUP8qkzHSAFYgw\r\n" + "NA5XaRxc55Guo9gRQQKj9/o9iTRoZZEuwA7oIguOVvEcGH9axJNFs4kCgYEA4hbW\r\n" + "YKrJMIdnb0Lbj0sUUbgXvbxUHpdL0iRKGGpZC7qauEUWyML+TqGQt47A9bsOxpuo\r\n" + "ZiHKcdeJ+Y6+S6klzTtUXFHnNnVtVj/d1TJe2WaiXWJPWOip1MzkmeaW7GlyZAG9\r\n" + "2ERB1pDv76e0ZefgLN5kCnbRb/dsEtyTz8IyPb0CgYA6ULvjFKRNnvz18dFswgCT\r\n" + "7Jts+OF42qbRM+wzBHqPfjZYNjlYWot2ER12yKxygTyXXFCfauZLzZUn3yTny5h1\r\n" + "mNdvfujfkTawbIOi7lpF2wItM4/CLATTUj0KrjsiibUx251t+K9T4X29cICDV0NO\r\n" + "qRDg3YAuP5I9ng64wrbpSQKBgEb9aL7doWKNgZrb4Vjy+CRYq4u18KvSUcpf/qv/\r\n" + "6InYQ/CMMQVExNknvesE9e2ymIcgJRY8kfaA+R/VBEd5ixcQBAMg7HqbEIO+dgcV\r\n" + "U9brdRvhXIzMMVdSJo10a/s7eOGR8mxPsmSPCee0Pt6omik8gykN+eEwTUz22aqo\r\n" + "jWH5AoGAYWd+y1wcI4ZkqdnoGbFapo2BjeZmFEV5KUhXWW7eJCmh6iD6hWr5b1ZR\r\n" + "6aQQyUNITq40JvIkTpgNO7bJ49+yL0SbCQXiJLoH2nvLK7sGLYOq0GQxD2sn3eLW\r\n" + "/qKTFd4LAK6dCMklQzr1Ev9cWMFm0DLUdOnKNv6zvme67Gs9xPE=\r\n" + "-----END RSA PRIVATE KEY-----\r\n"; StringReader reader = new StringReader(privateKey); RSAKeyPair keyPair = RSAPrivateKey2.KeyPairFromPem(privateKey); ServerCfg cfg = new ServerCfg(clientId, keyPair.Private); Authentication auth = new Authentication(cfg); _protocol = auth.CreateClientProtocol(); } public void StatUser(string email) { BasicUserInfoResponse response = _protocol.StatUser(email); if (!response.Message.HasActivated) { Console.WriteLine("The user account is not activated. Check your email and click on the activation link."); System.Environment.Exit(1); } else { Console.WriteLine("Have you authorized this application?"); string userResponse = Console.ReadLine(); if (!userResponse.ToLower().StartsWith("y")) { Console.WriteLine("Got to this URL and authorize the application: " + response.Message.AuthorizationUri); Console.WriteLine("Press 'Enter' once you have allowed this application."); Console.ReadLine(); } } } public void Authenticate(string email) { _delegation = _protocol.CreateDelegatedProtocol(email); } public NodeResponse BrowsePath(string path) { int children = 1; // Immediate contents only return _delegation.Navigate(new AbsolutePath(path), children); } public void UploadFile(string localFile, string remoteFolder) { Console.WriteLine("Uploading '{0}' to '{1}'...", Path.GetFileName(localFile), Path.GetFileName(remoteFolder)); FileStream stream = new FileStream(localFile, FileMode.Open); UploadFileRequest.Builder builder = UploadFileRequest.CreateBuilder(); builder.Name = Path.GetFileName(localFile); _delegation.PostFile(new AbsolutePath(remoteFolder), builder.Build(), stream); stream.Close(); } public void CreateFolder(string newFolder) { Console.WriteLine("Creating '{0}' folder...", Path.GetFileName(newFolder)); CreateFolderRequest.Builder builder = CreateFolderRequest.CreateBuilder(); _delegation.CreateFolder(new AbsolutePath(newFolder), builder.Build()); } public void Copy(string folderToCopy, string remoteFolder) { Console.WriteLine("Copying '{0}'...", Path.GetFileName(folderToCopy)); _delegation.Copy(new AbsolutePath(folderToCopy), new AbsolutePath(remoteFolder)); } public void MoveFile(string fileToMove, string remoteFolder) { Console.WriteLine("Moving '{0}' to '{1}'...", Path.GetFileName(fileToMove), remoteFolder); _delegation.Move(new AbsolutePath(fileToMove), new AbsolutePath(remoteFolder)); } public void MoveFolder(string folderToMove, string remoteFolder) { string folderName = Path.GetFileName(folderToMove); remoteFolder += String.Format("/{0}",folderName); Console.WriteLine("Moving '{0}' to '{1}'...", Path.GetFileName(folderToMove), remoteFolder); _delegation.Move(new AbsolutePath(folderToMove), new AbsolutePath(remoteFolder)); } public void ModifyFile(string remoteFile, string description) { Console.WriteLine("Modifying '{0}' description to '{1}'...", Path.GetFileName(remoteFile), description); UpdateNodeRequest.Builder updateBuilder = UpdateNodeRequest.CreateBuilder(); updateBuilder.Description = description; updateBuilder.UpdateDescription = true; ChangeNodeRequest.Builder changeBuilder = ChangeNodeRequest.CreateBuilder(); changeBuilder.Update = updateBuilder.Build(); _delegation.Update(new AbsolutePath(remoteFile), new NodeOptions(), changeBuilder.Build()); } public void ModifyFolder(string remoteFolder, string description) { Console.WriteLine("Modifying '{0}' description to '{1}'...", Path.GetFileName(remoteFolder), description); UpdateNodeRequest.Builder updateBuilder = UpdateNodeRequest.CreateBuilder(); updateBuilder.Description = description; ChangeNodeRequest.Builder changeBuilder = ChangeNodeRequest.CreateBuilder(); changeBuilder.Update = updateBuilder.Build(); _delegation.Update(new AbsolutePath(remoteFolder), new NodeOptions(), changeBuilder.Build()); } public void DeleteFile(string remoteFile) { Console.WriteLine("Deleting '{0}'...", Path.GetFileName(remoteFile)); _delegation.DeleteFile(new AbsolutePath(remoteFile)); } public void DeleteFolder(string remoteFolder) { Console.WriteLine("Deleting '{0}'...", Path.GetFileName(remoteFolder)); _delegation.DeleteFile(new AbsolutePath(remoteFolder)); } } }
Program.cs
using System; using System.Diagnostics; using System.IO; using System.Linq; namespace HelloWorldSVRest { class Program { static void Main(string[] args) { try { SmartVault smartVault = new SmartVault(); Authenticate(smartVault); //Upload file Console.WriteLine("\nLet's upload a file to \"My First folder\"."); string localFile = GetLocalFile(); string remoteFolder = GetRemoteFolder(smartVault, "My First folder"); smartVault.UploadFile(localFile, remoteFolder); Console.WriteLine("Upload complete"); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Create folder (folder_1) Console.WriteLine("\nLet's create a folder."); Console.WriteLine("What do you want to call the folder?"); string folder_1 = Console.ReadLine(); string remoteFolder1 = GetRemoteFolder(smartVault, folder_1); smartVault.CreateFolder(remoteFolder1); Console.WriteLine("'{0}' has been created.", folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Move file to folder_1 Console.WriteLine("\nLet's move the file into '{0}'.", folder_1); string remoteFile = GetRemoteFile(remoteFolder, Path.GetFileName(localFile)); string newRemoteFile = GetRemoteFile(remoteFolder1, Path.GetFileName(localFile)); smartVault.MoveFile(remoteFile, newRemoteFile); Console.WriteLine("'{0}' has been moved to '{1}'", Path.GetFileName(remoteFile), folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Make a copy of folder_1 (folder_2) Console.WriteLine("\nLet's make a copy of {0}.", folder_1); Console.WriteLine("What would you like to name the copy?"); string folder_2 = Console.ReadLine(); string remoteFolder2 = GetRemoteFolder(smartVault, folder_2); smartVault.Copy(remoteFolder1, remoteFolder2); Console.WriteLine("'{0}' has been copied", folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Move folder_2 inside folder_1 Console.WriteLine("\nLet's move '{0}' inside '{1}'.", folder_2, folder_1); smartVault.MoveFolder(remoteFolder2, remoteFolder1); Console.WriteLine("'{0}' has been moved inside '{1}'.", folder_2, folder_1); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Modify folder_1 properties Console.WriteLine("\nLet's modify the description of '{0}'.", folder_1); Console.WriteLine("What would you like to update the description of the folder to?"); string folderDescription = Console.ReadLine(); smartVault.ModifyFolder(remoteFolder1, folderDescription); Console.WriteLine("The description of '{0}' has been updated.", Path.GetFileName(remoteFolder1)); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Modify file properties Console.WriteLine("\nLet's modify the description of '{0}'.", Path.GetFileName(localFile)); Console.WriteLine("What would you like to update the description of the file to?"); string fileDescription = Console.ReadLine(); smartVault.ModifyFile(newRemoteFile, fileDescription); Console.WriteLine("The description of '{0}' has been updated.", Path.GetFileName(newRemoteFile)); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Delete file Console.WriteLine("\nLet's delete '{0}'", Path.GetFileName(newRemoteFile)); smartVault.DeleteFile(newRemoteFile); Console.WriteLine("'{0}' has been deleted.", Path.GetFileName(newRemoteFile)); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); //Delete folder Console.WriteLine("\nLet's delete '{0}'", Path.GetFileName(remoteFolder1)); smartVault.DeleteFolder(remoteFolder1); Console.WriteLine("'{0}' has been deleted.", Path.GetFileName(remoteFolder1)); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } Console.WriteLine("\nPress any key to exit"); Console.ReadKey(); } private static void Authenticate(SmartVault smartVault) { // Autonomous authentication Console.Write("Enter your email address: "); string email = Console.ReadLine(); smartVault.StatUser(email); smartVault.Authenticate(email); } private static string GetLocalFile() { Console.WriteLine("Enter the path to a file to upload. " + "(Hint: drag a file to the console window): "); string localFile = Console.ReadLine(); return localFile.Replace("\"", ""); // Remove quotes, if supplied } private static string GetRemoteFolder(SmartVault smartVault, string folderName) { var rootNode = smartVault.BrowsePath("/nodes/pth"); string account = rootNode.Message.ChildrenList[0].Name; return String.Format("/nodes/pth/{0}/My First Vault/{1}", account, folderName); } private static string GetRemoteFile(string remoteFolder, string fileName) { return String.Format("{0}/{1}", remoteFolder, fileName); } } }
Leave A Comment?