Getting file path in wcf assembly

I have an assembly referenced by a WCF service hosted in IIS. Some XSLT files are used in the assembly, and I'm confused where to dump these files or create a folder in the assembly project itself or in the WCF service, and how can I get the physical path to the xslt file in the assembly?

+5
source share
4 answers

Since WCF services that support IIS tend to copy the DLL to a temporary folder rather than the contents of a project that is configured to copy for output, you must reference the actual dll code base.

var codeBase = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
                    codeBase = codeBase.Substring(8); //Remove the "file:///" prefix in front of the actual path.

var dir = codeBase.Substring(0, codeBase.LastIndexOf("/", System.StringComparison.Ordinal) + 1); //Cut out the dll file name.

var file = @"ErrorMessages.xml";

var targetPath = dir + file;
+3
source

Try using AppDomain.CurrentDomain.RelativeSearchPath

+1

, Copy to Output Directory.
, , , :

var dllPath = Path.GetDirectoryName(  
    System.Reflection.Assembly.GetExecutingAssembly().Location);
var targetPath = Path.Combine(dllPath, "XsltFolder");
0

XSLT XML WCF, :

if (HttpContext.Current! = null) {// "~ /" provides the root physical folder of the WCF service virtual directory that supports this DLL ..., // for ex: E: \ PhyPath \ WCFServiceFolder \ RequestPhysicalPath = HttpContext. Current.Server.MapPath ("~ /"); }

0
source

All Articles