Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a C# window form application now i want to create a module where teachers can store files of different kinds like pdf.docx.jpeg etc in that directory and students can then access it to download those files.

i am planning to use database table to store directory path of a particular course where a teacher will upload all the files,books related to that course and then the students can see them in a list type manner in some form and can download whichever file they selected.

issue is that i want teacher to upload the files to a specific directory from which he can not navigate anywhere else in the pc/desktop.if i use openfiledialog in c# then person can easily wander through all the directories each folder.

i want this to be limited to only one folder from which he cannot go anywhere else.

and the other thing is how to download them for students after they are being uploaded by the teacher/lecturer

btw i read somewhere that its good to save files using file system instead of saving in databases that's why i dont want to save files in database tables

What I have tried:

tried using list view for getting file names in listview form but can only read name s of files cannot download the content
and used filedialog to save files in a directory but thats not giving the privacy for security as the teacher/lecturer can wander through all files and folders in the desktop/pc
Posted
Updated 21-Jun-19 23:26pm
v2
Comments
PeejayAdams 21-Jun-19 9:56am    
There's no inbuilt property of OpenFileDialog that will do that (though it would be rather useful!).

You could add code to the FileOK event to compare the path, otherwise you'll need to create your own version of the control.

Further to Bill's comment, you could start with the FileDialog Class (System.Windows.Forms) | Microsoft Docs[^] and add your own extended code to control where the user can look. However, if you use a ListView then the user does not need to select the location of the files. Just provide a list of filenames and keep the directory name hidden.
 
Share this answer
 
Comments
BillWoodruff 22-Jun-19 5:46am    
+5 I once ... long ago, while running a computer classroom for kids ... made file upload (by teachers) a bit too easy: you can easily imagine what happened :)
Richard MacCutchan 22-Jun-19 5:53am    
Lots of happy kids. :)
BillWoodruff 22-Jun-19 5:58am    
Unfortunately, lots of angry parents when their kids brought home a print-out of a certain file that one of their intrepid classmates had posted by hacking. That student is now a well-known software entrepreneur in California who is worth many million$.
The answer is simple: do not use 'SaveFileDialog and 'OpenFileDialog; use hard-coded paths. Use administrative tools to control permission to access, upload, and download ... of folders, and files.

[edit] Essential we know if your app is running on a server, and you can control access; or: are both students and teachers running your app ... both running the same app ? The files are on a server ?

If you want both students, and teachers to run an app (locally), I'd make two dedicated apps, one for students, one for teachers.
 
Share this answer
 
v2
Comments
Member 12899279 22-Jun-19 14:23pm    
i am developing a student portal so no i cannot develop two separate apps for students and teachers.
and other then this i didn't get what do you mean by hard coded paths.
files are on my pc and this a desktop application , both students and teachers will access it via a same pc/desktop.
i want to save files using filestream because its not wise to use sql database to store files in it though we can
BillWoodruff 22-Jun-19 17:56pm    
If you are allowing access by both students and teachers, to the same app, on the same machine that has the actual files: there is nothing I can say that would be helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900