Solved

using reflection , or any means, how can I get the name of a source code file at runtime?

Posted on 2014-04-01
6
425 Views
Last Modified: 2014-04-05
using reflection ,or any means, how can I get the name of a source code  file at runtime?
0
Comment
Question by:HLRosenberger
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39970249
What version of .NET and/or Visual Studio are you using?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 167 total points
ID: 39970585
Which source code file? The one from which the executing method comes, or something else?

You can get the source file of the executing method using:
System.Diagnostics.StackTrace stack = new System.Diagnostics.StackTrace(true);
string executingFile = stack.GetFrame(0).GetFileName();

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 167 total points
ID: 39971448
For this to work, you need to make sure that you "Generate debug info" in the Advanced Compile Options (Compile tab of the project's Properties window) and that you distribute the .pdb file that is generated along with the application.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 166 total points
ID: 39977105
Hi HLRosenberger,

I use the following to determine exact source of error using system.reflection.methodbase()
      Try
        ' ...

      Catch ex As Exception
        Dim sf As System.Diagnostics.StackFrame = New System.Diagnostics.StackFrame()
        Dim mb As System.Reflection.MethodBase = sf.GetMethod()
        Session("ErrorMessage") = "Error in " _
          & Context.Request.Url.ToString().Replace(Context.Request.Url.GetLeftPart(UriPartial.Authority) & VirtualPathUtility.ToAbsolute("~/"), "~/") _
          & "." & mb.Name _
          & "<br />" & ex.Message _
          & "<br />" & ex.Source
      End Try

Open in new window

Respectfully yours,
Alan
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 39980521
thanks
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39980775
I see my question was completely ignored. I asked it for a reason. If you're working under .NET 4.5, then you might investigate The CallerFilePathAttribute class.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now