2

I have a .net project whose part of the functionality is xls transformation.

I now want to move that functionality away from the main project to a separate class library project.

I have no problems moving classes and accessing them, but part of the resources that I wanted to move were xslt files that define the transformations. Those files were originally located in the special asp.net folder: App_Data and then accessed using Server.MapPath(~/App_Data/XSLT/anXsltFile.xslt)

I wanted to move those files to that separate library as well, but not sure how to approach it, and how to access those files within the class library.

padn
  • 1,959
  • 4
  • 16
  • 15
  • I think a class library, unlike a web site project, should not have file resources. It should supply the functionality to the web site project which will host the files. Just my 2 cents. – Elad Lachmi Mar 30 '11 at 15:10
  • @Elad - those were my thoughts as well, I think about leaving the xslt files in the resource location of the main project and give the reference to them to the class library. But at the same time those files are specific to functionality of that class library so I am not sure. – padn Mar 30 '11 at 15:14
  • I personally consider both the class library and the xslt files to be resources of the web site. Lets say you want to use this same class in a different app or web site, with different xslt files. Re-usability is the word :) – Elad Lachmi Mar 30 '11 at 15:24
  • @Elad - yes, it makes a perfect sense. that also means that there is no need to rebuild the class library if those xslt files are updated. Can you add an answer with this option? Thanks – padn Mar 30 '11 at 15:30

4 Answers4

3

Perhaps embed the xslt files inside your class library and stream read them as necessary to perform your transforms

http://support.microsoft.com/kb/319292

How to embed a text file in a .NET assembly?

http://blogs.msdn.com/b/alexdan/archive/2007/12/19/loading-embedded-resources-in-c-using-getmanifestresourcestream.aspx

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/1d341eae-fed4-408c-8791-96e96a5fd99c/

Community
  • 1
  • 1
Hawxby
  • 2,746
  • 21
  • 29
  • thanks Hawxby and +1 that looks like the way to go if I wanted to keep the resources embedded within the library. The xslt files in my case can change with time so I am going to go with Elad's suggestion – padn Mar 30 '11 at 15:56
1

I think a class library, unlike a web site project, should not have file resources. It should supply the functionality to the web site project which will host the files. I personally consider both the class library and the xslt files to be resources of the web site. Lets say you want to use this same class in a different app or web site, with different xslt files. It's bad for re-usability.

Elad Lachmi
  • 10,406
  • 13
  • 71
  • 133
0

I suggest you to use string constant in Web.Config with the Server.MapPath path and use these to load the xslt files.

I hope it's helpful

Faber
  • 2,194
  • 2
  • 27
  • 36
0

if you mantain the xsltfiles on the app_data, you must use

httpcontext.current.server.mappath("...your path...")

if you move the xslt files to the assembly too, you must get the Assembly resource...

Flavio CF Oliveira
  • 5,235
  • 13
  • 40
  • 63