1

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?

Hossain Muctadir
  • 3,546
  • 1
  • 19
  • 33

3 Answers3

1

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.

Josh Earl
  • 18,151
  • 15
  • 62
  • 91
  • Thank you all. but the problem is images under the Project1 are kept in a folder say /Images and these images can be updated, deleted and added from project1. – Hossain Muctadir Feb 01 '12 at 18:09
  • I think I get it. The _users_ can add, edit or delete files, not just developers. If that's the case, you should update your original post to clarify. It sounds like you're trying to share things like your website's logo across multiple projects. – Josh Earl Feb 01 '12 at 18:44
0

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.

David Merriman
  • 6,056
  • 1
  • 18
  • 18
0

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.

Community
  • 1
  • 1
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • Thanks. but the problem is the files can be added, deleted or updated from the Project1. – Hossain Muctadir Feb 01 '12 at 18:15
  • 1
    My solution does not include putting the files in Project1. You may want to read the entire post... – Erik Philips Feb 01 '12 at 18:17
  • As I understand, you are adding link of the file to the projects. What will happen if an user adds a new image file from the front end? How am i supposed to add link to the file? – Hossain Muctadir Feb 01 '12 at 18:27
  • I'm sorry I did not read that this was at runtime. My solution would not work in that case. Updating with an alternate solution. – Erik Philips Feb 01 '12 at 19:27