I have an assembly that contains a function that could be called from IIS or from a console app.
Because of this I have opted for the following to get the path:
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
obviously this will return the bin directory in the case of the function being called from IIS.
I intend to create a txt file on this path. Is it such a bad idea to have text files sitting in the bin directory? Please give valid objections (if any) why this could cause problems.
Assembly.Locationcan return surprising results, e.g. if shadow copying is turned on (for instance, when running through NUnit), or when running from a location not on the local file system (you can run .NET apps over HTTP).AppDomain.CurrentDomain.BaseDirectoryis a safer option, as it returns the original path prior to shadow copying (although in the case of HTTP deployment I think it returns the directory whereieexec.exeis located).The safest option is to embed whatever data you need as a resource within the assembly, and use
Assembly.GetManifestResourceStreamto access it at runtime.