Created
December 9, 2014 18:35
-
-
Save evernotegists/793b9c5cf61276e21b68 to your computer and use it in GitHub Desktop.
Convert a resource hash to a byte array for noteStore.getResourceByHash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// To be used alongside our Cloud SDK: https://github.com/evernote/evernote-cloud-sdk-ios | |
/// "hashCode" below is the "hash=" value extracted from the en-media tag | |
byte[] bytes = ConvertStringToByteArray(hashCode); | |
Resource resrc = enNoteStore.getResourceByHash(authToken, noteGuid, bytes, true, false, false); | |
string resourceContent = Convert.ToBase64String(resrc.Data.Body); | |
/// The function convertStringToByteArray is: | |
private byte[] ConvertStringToByteArray(string stringToConvert) | |
{ | |
int length = stringToConvert.Length; | |
int upperBound = length / 2; | |
if (length % 2 == 0) { | |
upperBound -= 1; | |
} else { | |
stringToConvert = "0" + stringToConvert; | |
} | |
byte[] bytes = new byte[upperBound]; | |
for (int i = 0; i <= upperBound; i++) { | |
bytes(i) = Convert.ToByte(stringToConvert.Substring(i * 2, 2), 16); | |
} | |
return bytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment