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
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 75

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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