Here is my use case: the user will click a "save" link and will be presented with a filepicker.export() dialog, choose a location and name and save a file. Here's the exotic part: I won't have the file yet at that time. It needs to be downloaded first with a GET request, and then stored in filepicker. I won't know which file to start downloading until the user clicks "save".
This can be dealt with by first downloading the file when the user clicks "save", and only then displaying the filepicker.export() dialog. However, I find this cumbersome, since the user will have to wait for the download to finish to be able to choose a filename and location.
It would be much better to allow the user to first make their choice, for example "Dropbox/image.png", and store some sort of placeholder while the download is running: "Dropbox/image.png.part". Later, when the download finishes, I could write the data to the file and rename it to "Dropbox/image.png".
Here are my questions:
Is it possible to append ".part" to the filename that the user chose in the filepicker.export() call?
More importantly, while I know how to write to the file when the download is done, is there any way to rename it? I tried creating a new fpfile object with the same filepicker URL and a different filename, the new filename was ignored (though the write succeeded).
My recommendation would be to first call filepicker.export call on an empty file and allow the user to specify both the name of the file they would like and the location in their cloud storage. When the filepicker.export call finishes, it will pass an FPFile into the callback. From there, you can download any necessary contents you need and do a filepicker.write to save the contents to the location selected by the user.
There shouldn't be any need to rename the file, as the user has already provided the name they want to save the file under during the filepicker.export() call.
Related
I am using dio and path_provider to save pdf from url, I am going to show that pdf to user using open_file. But I have problem with saving path.
Where I can save file temporary, show that file, and after some time or when user will not look at the app delete file? File can be even deleted after 2 days. Time when pdf will be removed is not that important.
It can be even longer time, but sooner or later it must happen. This is in order to not have old pdf's stored on the phone in case of pdf's change on the web
Right now it is my path:
var tempDir = await getTemporaryDirectory();
String fullPath = "${tempDir.path}/test.pdf";
edit: there is also a second option, to check if something is in this place saved, if yes, then remove it and download again, but this place can not be shown to a users, I found "getApplicationDocumentsDirectory", this allows me to save pdf in place where users can not read a pdf.
After that reaserch my question will be, If I download my pdf in a way as you can see above it will stay in that place and will never be moved? Now I need to only creade a methode that will see if my pdf is there end will remove it? How to extract name of my pdf I will need that?
I guess you have selected the right path if you just needed to delete the file for the space on device because when you use the getTemporaryDirectory() the system will automatically delete files in this directory as disk space is needed elsewhere on the device. The system will always delete older files first, based on the lastModifiedTime.
But if you want to check if the file changed or not you can send in the response of the file a flag that contains the last updated date and this value can be the file name prefix, so when ever you open the app you can check if the date has changed you will delete the old one manually and store the new one.
If you follow this solution it will be no need to use getTemporaryDirectory() you have to use the getApplicationDocumentsDirectory()
When a user double clicks an item in one of my files, it opens a temporary file for them to edit using DTE. Once they are done editing that temporary file they close it and it adds to the parent file. That works great.
My issue is, is that when they go to close the temporary file, it asks them if they want to save. In this situation clicking no is the right thing to do else it asks you to save the file as something. Is there a way of changing this so that it doesn't ask the user and always just closes the file without saving it?
Thanks in advance.
While the DTE methods don't expose a way to do this, you could leverage IVsUIShellOpenDocument instead, and then explicitly add the RDT_DontSave, RDT_DontSaveAs, and potentially the RDT_DontAddtoMRU flags, via the grfOpenStandard argument passed to IVsUIShellOpenDocument.OpenStandardEditor or similar.
Alternatively, you could use IVsRunningDocumentTable.ModifyDocumentFlags to add the flags after the fact.
But for that, you'll need to retrieve the document cookie with something like IVsRunningDocumentTable2.FindAndLockDocumentEx.
We have a system where we are generating a report as a Word document (using RDLC).
The report is created in a temporary directory, and then Word is launched to display it to the user.
Word is launched, and the report loaded by:
_wordApplication = (Word.Application)Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
object tempFileNameObj = documentPath;
_wordDocument = _wordApplication.Documents.Open(ref tempFileNameObj);
What I want is to convince Word that this is really a newly created, unsaved file, so it will give the user a SaveAs dialog when they save it (rather than save back to the temporary location).
Ideally, I would like to be able to specify the target directory, and offer a default name.
While the Word is being launched, I can do what I like using Automation, but after Word has been launched, my application will be disconnected from Word, and I would prefer not to leave any macros floating around in the document.
You can rename your .doc file to .dot (Word Template) and if you launch it afterwards, it will create a new File looking exactely like your .doc
If you're not using a macro I believe that the only way to archieve this would be to save the file that they will download be a read-only or user defined template file this way if they wan't to make changes to it they wil have to save it with another name in their computer to save the changes made. If you can use a macro you can archieve more options and even force a save as dialog when the document is opened or when it's closed. I hope this helps as I couldn't find any more information without using a macro.
Here is a situation I have a data file in document directory which is being updated in the application every now and then. So I want to save it to my desktop using iTunes. But I don't want that the file should be uploaded back to my application. i.e. I want that user can download the file but can not upload any.
I was thinking to have the data file on some other location like Library and put a button on application settings saying "Prepare backup" that will copy that data file in Document directory, from where user can download it. If user uploads any thing it won't make any difference as my current file is in Library directory.
This is just a thought,
can anyone suggest me other way or the above way is good to go?
Edit: I just need that after the successful export user can view the data file (may be later) without support of the application.
You can't.
But what you can do is check (using an timer every 10 seconds) if a new file is added to the documents directory and then delete it programmatically.
But this ofcourse doesn't disable the replacement of files.
I have an .xml file that is going to be shipped within my app.
This file contains values that are read from it and saved as an array when the app launches.
Each time the app is run, I want to check with the server if there is an internet connection. If so, I want to get the newest version of the .xml file from the server and replace the one that I currently have saved in my app (this way, the next time the user logs in and doesn't have internet access, he/she will be able to use the old (yet most up to date) data).
What is the best way to do this?
Thanks,
The best way to probably do this is to copy the XML file from the app bundle to a location in the app's sandbox, e.g. the Documents folder. Thereafter you can update the XML content as necessary with newer data from the server. The copy is necessary to allow you to write to the file, since you cannot change the content of your app's bundle because it is signed.
Alternatively, if the data is simple enough, you can just save it to user defaults on first launch and change the defaults on subsequent updates
I might skip the XML altogether, unless it contains a baseline of default settings, and just sync user defaults over the Internet. You can't modify files in the bundle, so your only option would be to copy over a "default-settings" XML file to the application's Documents folder to make it editable.