How to make files accessible to all users on Visual Basic app - pdf

I am attempting to make an instructional app for the call canter that I work at. Part of the code allows users to display information through the use of several files in our directory with drop down combo boxes.
For instance, a small portion of the code is similar to this (I did not save the app and bring it home so I am going off memory):
If cboGlossaryTerm.SelectedItem("MSN")Then
Process.Start("S:\MSN.pdf")
End If
I put the pdf files in My Resources and the Word files are added under the Solution folder.
I am using filepaths in the code as well.
(I attempted to save the pdf files in the Solutions folder but the pdf was not compatible.
With me adding the files this way, will users who do not have access to the S drive folder be able to display the files? Also, will the files remain accessible in the program if they are deleted from the S drive? If not, how should I be referencing the files in my project? Do I have to reference the pdf files from My Resources? If so, how do I do that in an If-Then statement similar to the one above?

from what you have there it doesn't look like the pdfs in the S:\ would be available to anyone who doesn't have the drive mapped on their local machine.
as for if the files are deleted, if they are being loaded from the S:\ then when they are deleted from there the program will not be able to find them to load them.
if the program is being installed on the local machines you might want to look at just including the pdfs in the installer and accessing them through the program files path.

Related

Vaadin 8 multiupload with folder selection

I need to upload files and folders to the server while preserving the hierarchy. At the moment I am using a plugin multiFileUpload that allows you to upload multiple files at the same time, but it ignores the selected folders. I know that neither vaadin nor Html5 has a universal solution that works everywhere for uploading folders.
I'm ready to write my own solution, but climbed the Internet can't find a way to display file selection (perhaps there will a JavaScript call) but the main question - is it possible somehow to POST a request Vaadin's and upload files by way of creating subfolders in which they were?
You can only upload files, not folders. It's simply not doable.
You can upload any number of files, but they won't be structured into folders.
I see two possibilities how you could still achieve what you need if you really wanted to, even if it changes the user experience a bit:
Let the user upload a .zip file of his folder structure. When they upload it, you unzip it on the server side and have now access to all the files in the correct folder structure.
Let the user upload all his files within his folder structure. After all files have been uploaded, You display all the files in a TreeGrid where the user can recreate the original structure using Drag-and-Drop or similar.

Preventing other application from opening custom file vb.net

I have a text file. Now I have changed its file type from .txt to .abc. My VB.NET program loads the text into textboxes from that file. After changing the file type, however, other apps like NotePad and Word are able to open and read my .abc file.
Is there any way that only my application will be able to open/read from the file and no other app would be able to do so? What I mean is, suppose I have a PhotoShop document .psd file, no other app, rather that photoshop itself, can open it. How do I make my file unreadable by other apps?
There is no way to prevent an app that you don't develop from opening any file. The extensions are just there for helping us humans, and maybe a bit for the computer to know the default app you select for an extension.
Like you said, a .txt file can be opened by many many apps. You can open a .txt file with Notepad, Firefox, VSCode, and many others.
Same way, a .psd file can be opened by many many apps. You can open that .psd file with Photoshop, but also Notepad, Firefox, and VSCode, and probably the same apps as above.
The difference is which apps can read and understand the file.
In order to make a file not understandable by other apps, you need to make it into a format that cannot recognize, because you planned it "in secret".
Like Visual Vincent said above, you could encrypt the file in a way, or you can have a binary file, that basically only your app knows know to understand.
Since you dont own the app you want the file to be understood by, then you either have to accept that it can be opened by any app that can open files, or you can try to encrypt the file outside the app, or like zipping it with a password, and then decrypting or unzipping when you want to use it.
Firstly, any file can be read unless it is still open by a particular process or service. Even PhotoShop files can be 'read' by NotePad - try it!
So, an attempt at my first answer...
You can try a couple of methods to prevent opening the file, for instance, applying a file lock. As an example, SQL Server .mdf files are locked by the SQL Server service. This happens because the files are maintained in an open state, however; your application would have to remain running to keep these files open. Technically, though, the files can still be copied.
Another way is to set the hidden attribute for the file. This hides the file from the less savvy users, but it will be displayed if the user show's hidden files.
And my second answer: You refer to the format of files by saying only PhotoShop can read or write its own files (not true, but I know what you're saying).
The format of the file must be decided by yourself. You must determine how you are going to store the data that you output from your application. It looks like you have been attempting to write your application data into a text file. Perhaps you should try writing to binary files instead. Binary files, while not encrypted, as suggested by Visual Vincent in the comments to your question, still provide a more tailored approach to storing your data.
Binary files write raw binary data instead of humanised text. For instance, if you write an integer to the file it will appear as a string of four bytes, not your usual 123456789 textual format.
So, you really need to clarify what data you want to write to the file, decide on a set structure to your file (as you also have to be able to read it back in to your application) and then be able to write the information.

Writing to a document's enclosing folder

When you open an XCode project it can automatically write to the enclosing folder of the respective .xcodeproj file.
In a sandboxed application you can only write to files that are opened, or write to directories that have been opened with NSOpenPanel.
What I'm trying to achieve is the same functionality as XCode ; my app makes a project file (a document much like an .xcodeproj file) that is saved to a user-selected directory, and within that directory other files are created relating to that project file. However, if the file is re-opened after terminating the app, I end up losing permission to write to the enclosing directory.
I see bookmarks are an option but they do not provide the same functionality. If the project file is moved to a new directory it makes no sense to keep writing to the old directory, and I'd have to ask the user for permission to write to the new directory. I don't find this user-friendly. Is there absolutely no way to resolve this problem?
If the project file is moved to a new directory it makes no sense to keep writing to the old directory, and I'd have to ask the user for permission to write to the new directory. I don't find this user-friendly. Is there absolutely no way to resolve this problem?
Unfortunately for you this is Apple's sandbox model and you need to adapt to it. The process you describe is a good way to handle your situation - when you first create a project file ask the user to select the folder to store it and save a bookmark to that folder, when an existing project file is opened check whether you have a saved bookmark for its parent folder and if not put up a dialog explaining the file has been moved and ask the user for permission to use the new parent folder and keep a bookmark to it.
Users are used to these dialogs from apps, the sandbox has been around a long time. You might find keeping a number of saved bookmarks and optimising your collection will improve your users experience. E.g. remember that a bookmark to a folder grants access to all the files and folders within it, and the files/folders within those folders, etc. This means if a user reorganises by moving projects into sub folders may not require you to ask for a new bookmark, and similarly when a new bookmark is acquired any existing ones you have stored to folders contained by the new bookmark's folder are redundant and can be removed from your collection of stored bookmarks.
Not the answer you really wanted, but hope it helps!

Monitoring a folder for a specific file

I have a program that uploads .txt or .rje files from a folder. Now when you put any other file format into the folder, like .jar, then the application crashes.
Now I cannot change the mechanics of the application, so I would like to know if there is a type of program/script that I can use that monitors the folder for any files that are non-txt/rje and then move them out of the folder once they are put there...
Is this possible using a script? (I do not want to use a .exe application to do this...not allowed to install 3rd party software onto the server this folder exists...)
Thank you
Your solution won't work as you have a race condition between the program doing the upload and the one doing the deletion. If upload runs first it still crashes.
The correct solution is to modify the upload program to cope with this scenario.
If that is not possible then the only safe work around would be to use a new folder to drop the files in, have a script run that constantly scans the folder and if a new file appears either move it to the processing folder or deletes it as appropriate.
(For the actual detection that's not my area of expertise but the simplest would be to have a bat file that just runs periodically (or even just runs once and loops with a wait, check, move, wait, check, move, etc) and processes everything in the folder when it runs).

Recommended document structure. File Wrappers? Roll my own?

I'm currently working out the best structure for a document I'm trying to create. The document is basically a core data document that uses sqlite as its store, but uses the Apple provided NSPersistentDocument+FileWrapperSupport to enable file wrapper support.
The document makes heavy use of media, such as images, videos, audio files, etc. with potentially 1000s of files. So what I'm trying to do is create a structure similar to the following:
/myfile.ext/
/myfile.ext/store.sqlite
/myfile.ext/content/
/myfile.ext/content/images/*
/myfile.ext/content/videos/*
/myfile.ext/content/audio/*
Now, first of all I went down the route of creating a temporary directory and placing all of my media in there. Basically creating the paths and file names '/content/images/image1.jpg' as I wanted them to appear in the saved file wrapper, and then upon save I attempted to copy these all into the filewrapper...
What I found was that the files were indeed copied into the wrapper with the file structure I wanted, but when the actual wrapper was saved, these files all magically disappeared.
Great.
So, I trashed my existing solution and tried to use file wrappers instead. This solution involved creating a content wrapper file directory when a new document was created, or loading in a content directory file wrapper upon opening a document.
When an image was added/modified, I created the necessary directory wrappers inside this root content wrapper (i.e. an images directory wrapper if it didn't already exist, or any other intermediary directory wrappers that needed to be created) and then created a regular file wrapper for the media, removing any existing wrapper for that file name if one was there.
Saving the document was just a case of making sure the content file wrapper was added to the document file wrapper, and the document would save.
Well... it did. The first time. However, any attempts to make any subsequent changes i.e add an image, save. Then replace image, save. Did not behave as expected, only showing the image from the first save.
So, my question is... first of all, which of the above approaches is the correct one, if at all, and what am I doing that wrong for them to fail.
And secondly, as I expect to be managing 1000s of images, is using file wrappers the correct way to go about things at all.
With that much media in play, you should likely give your users control over whether the media resides in the document or only a reference to the media is included in the document, and the media resides elsewhere, such as in a library/repository managed by your application. Then they could save out a (potentially many times larger) copy with all references resolved.
You might want to zip/unzip any directory so that users don't get confused trying to attach the document to an email. I believe iWork has been doing this with its document bundles for a while now.
As far as what you are doing wrong, no-one can say, as you haven't provided any code demonstrating what you are doing.
Why don't you create a one-off application that lets you select files on disk and saves those files in a document using a file wrapper? This would let you tackle this functionality without any interference from other issues in your application. Once you understand how to use file wrappers, you can port the code back or just write new code that works.