Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I'm developing a VB.NET webservice. It's purpose is to save data of employee identification badges (Name, Employee Number, Photo), so that the data can be accessed by different client applications later.

Name e.g. is saved into an SQL DB. But where to save the photo? It is given to the webservice as Byte Array and must be saved somewhere.

The webservice should save the Photo into a folder, so every client application can access the photo by calling a public URL e.g.
https://192.168.1.1/MyWebservice/Photos/Employee1234.jpg (as a subfolder of the webservice)
or like
https://192.168.1.1/EmployeePhotos/Employee1234.jpg (as separate URL)

Ideally the Picturefiles should be accessible in a shared folder, too,
in case a client application (e.g. the wage and salery software) does not support URLs but directory paths \\192.168.1.1\Photos\Employee1234.jpg only.

I'm uncertain what's the best practice:
- save the picture into a subfolder of the webservice (hazarding the consequences, that the subfolders content could be deleted by mistake during the deployment of a new release of the webservice)? How to access the Directoryname (any command like Server.MapPath?)
- does .NET provide special folders for problems like mine?
- save the picture into a directory outside the webservice folder? (Is this possible or are webservices sandboxed on the server?). And additionally a share on this folder to access the files by URL and Folderpath?

I would be grateful for your ideas and hints
Yours
Phil
Posted

1 solution

You could possibly make multiple sub-directories to hold different sort of images in your applications. The parent directory could be something like this, https://192.168.1.1/Images, then inside it you can create different folders for EmployeePhotos, ApplicationImages (such as the logo, social buttons etc). Do not create the folder MyWebService; clients know that the IP address targets your own service.

You can possibly use the Server.MapPath() function, if you're going to work around in the absolute paths. MapPath returns the absolute paths. Since you do not want yourself getting hands dirty, or to allow anyone else to use that absolute path to the directory, you can ignore it. :)

In .NET, you can possibly enumerate over multiple directories, and use which so ever directory over the machine that you like. A code to get directories from machine in .NET is like this,

C#
// Absolute path to the AppData folder; you can create your folder there
Environment.GetSpecialFolder(Environment.SpecialFolder.ApplicationData);


You can read this MSDN document[^], to learn more on this process.

That won't be a good idea, you can store the images right inside a local "Images" folder, that would indicate that inside your web service this folder is meant for the image data only.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Feb-15 20:51pm    
Agree, a 5.
—SA
Afzaal Ahmad Zeeshan 28-Feb-15 3:57am    
Thanks for your vote Sergey sir.

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