Reputation: 3626
I have a C# solution containing several MVC asp.net projects. Under Project1 there is a directory for storing images which can be edited, deleted and added by user from the front end.I need to access those images from the Project2. But, i don't want to hard code the file path. How can I do that?
Upvotes: 1
Views: 7188
Reputation: 54676
I've answered a similar question .Net MVC: How do you share scripts among multiple projects in one solution? where my answer works with any type of file (.html, .js, .png, .jpg, .cs, .css)
Update 1
For doing this at Runtime, I would create a database (MSSQL) and store the files in that database's FileStream (this does not store them in the MDF Database, Filestream vs Normal Files). This makes the files available to any project you create and you can add additional meta data (like the user) for additional authorization, logging and querying.
Option #1. Retrieving the files (images) can be done by any application and would then be served by that application. The advantage is any type of bandwidth usage can be easily and directly tied to the application serving the file. The disadvantage is that if your user is using your multiple sites, the file would not be cached by the browser cross websites.
Option #2. Retrieving the files (images) can be done by a seperate file share project. Each time another project needs a file, it can query the database, and create the appropriate URL to the file share project url and retrieve the image on the client side.
Upvotes: 0
Reputation: 18361
You can add the files as links (shortcuts) to your second project.
Here's a quick walkthrough.
Edit: Sounds like I misunderstood the original question. If you're looking to have access to dynamically created/deleted images across multiple websites, then you should probably look at creating a shared folder on your server and having use-modified files deposited there.
If you don't have a dedicated server that you can log into, you can probably still share files between your sites if you can set them up as virtual directories under a common site in IIS. They should both be able to access a folder that sits inside the site root.
Upvotes: 1
Reputation: 6086
This isn't a direct answer to your problem, but I believe it will help, if your images are resources within Project2: http://www.codeproject.com/Articles/2125/Using-Resource-only-Assemblies-with-C
Basically, you'll need to create a ResourceManager for the Project2 within Project1, and then use it to grab the resources. It should be pretty straightforward.
Upvotes: 0