Xamarin Android write to sd card to user accessible file - xamarin

I'm able to write to and read from the SD Card using this location: "/data/user/0/ASSEMBLY-NAME/files"
This works fine for internal app use, but the file is not accessible to a user.
Is there ANY way to create a file on the sd card in Xamarin.Android where the user can see it?
Is there a magic location on the sd card where I can create a file where the file will be visible by a user?
This concept seems so simple I would think it would take minutes to solve, but I've been at this for hours.
UPDATE SINCE ORIGINAL POST ...
Using the path from
Paths.ExternalStorage
gives the correct path to use to create/write/append to a file accessible to the user
var path = Paths.ExternalStorage + "/";
System.IO.File.WriteAllText(path + fileName, fileContents);
will write/create a file to the apps folder on the sd card
System.IO.File.AppendAllText(path + fileName, "\nappending to file");
will append to that file if it exists, or create it if it doesn't exist
The path I was using before, the
"/data/user/0/ASSEMBLY-NAME/files"
writes to the same location, but the files are inaccessible to the user
The files accessible to the user have to be viewed using a file viewer like ES File Explorer, but they can be viewed.
I hope this is helpful to anyone struggling with this issue like I was

Related

What is the format of a folder ID in Google Drive?

My question is similar to What is format of Google Drive's FileID ? I need to find out whether new File has been uploaded to my drive or not using API's but I want to know the format of a folder ID in Google Drive, the one that appears in the URL bar when you open a folder in your Google drive, the thing after https://drive.google.com/drive/u/0/folders/<this part>.
Google Drive folder id doesn't have a specific guaranteed format. This (apparent format which really isn't a format) has changed in the past and may change again.
Trying to create any kind of local verification of this will be futile.
The best option would be to do a Files: get and test if you get a response. This will work better as it will also verify that the user has access to the file as well as testing that its a valid file id format.
Any (regex) attempt to verify the file id wouldn't really verify it as its not going to test if the user has access.
A folder ID starts with a 1 followed by 32 base-64 encoded digits, except unlike base64 the + is replaced by - and / is replaced by _. You can use the following regex:
/^1[A-Za-z0-9-_]{32}$/

Google Drive api scope and file access (drive vs drive.files)

I have created two refresh tokens for me:
one for
SCOPE = 'https://www.googleapis.com/auth/drive'
and another
SCOPE = 'https://www.googleapis.com/auth/drive.file'
I'm trying to get information about files (using get method)
Some files I can get when using SCOPE drive.files, and some only when using wider scope drive
But I can not figure out what is the reason for that? Files are located in different folders but have one shared root folder.
The difference is that 'drive.file' only gives you permission to files that your app has created or the user has explicitly shared with your app, whereas 'drive' gives your app permission to see the all the files in the user's drive.
See
https://developers.google.com/drive/web/scopes
You should really look into using drive.file, that is where they are trying to push users. I was just fighting with this myself and found that if you use the drive.file scope, you can then subsequently open the file that is chosen using the API for the file type, but only if you set the correct AppID.
See here: https://developers.google.com/picker/docs/#gdata
This allows you to get past the 404 error that you get if you don't set the AppID.

DocsList findFolder() issue

This is a google spreadsheet script question.
I have a GUI setup in order to search for "SouthWest" and then find a "test" sheet. This is the code I am using.
var file = DocsList.getFolder("SouthWest").find("test");
This works just fine when I run it under my account (as I have this folder and file setup correctly) but when another user is logged into google docs it will attempt to search for this folder/file under the new user instead of the owner of the document. Is there a way to have it just search the DocsList of the owner of the spreadsheet that is currently open? The error that I get under the new user is "Error encountered: Cannot find folder SouthWest." Thanks.
If you always want to access the same file, you can use the getFileById method and address it directly instead of searching every time:
https://developers.google.com/apps-script/class_docslist#getFileById
Of course, you should make sure that all users are allowed to access that file.

Download large file from Skydrive to Windows Phone 7

Am having some trouble with the SkyDrive download process and hoping you can help me.
Following the standard SkyDrive API & examples, I've set up a page that browses the SkyDrive folder structure, lets User click on a file, prompt to download, and it all works correctly.
Where I'm having trouble is when the file downloaded is large, I get the OutOfMemoryException thrown at around the 100Mb mark.
Dennis speaks on this problem here http://dotnet.dzone.com/articles/2-things-you-should-consider but it relates to a direct URL download, not via the SkyDrive architecture.
I've tried extracting the URL from SkyDrive and doing the direct download that way but haven't had any success.
Here is the code I'm using - the "item" object is of type SkyDriveItem, having iterated through a folders content and selected this file.
LiveConnectClient downloadClient = new LiveConnectClient(App.Session);
try
{
downloadClient.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(downloadClient_DownloadCompleted);
downloadClient.DownloadProgressChanged += new EventHandler<LiveDownloadProgressChangedEventArgs>(downloadClient_DownloadProgressChanged);
downloadClient.DownloadAsync(item.ID + "/content", item);
This will work fine when the file isn't too large, but as mentioned, select a big file (>100Mb) and it dies with the OutOfMemory exception.
Any pointers?
Thanks in advance
Resolved - While I was never able to use the downloadClient.DownloadAsync() method to download large files, playing with the downloadClient.getAsync() and using the Pre-Authenticated URL via a regular Stream downloader does the trick.

Download file from Skydrive using SkyDrive Live

I'm using SkyDrive Live to upload files, but now I want to download the file I just uploaded. In the documentation it mentions a file ID but I'm not finding how I can get that ID.
I have a folder that I placed the file into so I would somehow need to pass the folder ID and then get the fileID...
Does anyone know how to do this or know of any tutorials on this?
If you uploaded the file with SkyDrive SDK, then you get the fileId by the UploadCompleted event's e.Result["id"]
If you have the folderId, but not the fileId, then you can query the content of the folder with client.GetAsync(folderId/files). The GetCompleted event's e.Result["data"] returns a IDictionary of file descriptions, each containing the fileId. In this cased you need to identify the required file by dictionaryEntry["name"] or some other magic..

Resources