Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm making a program with several forms and usercontorls, But there is a problem I face here,

How can I get the Physical address of a form that I'm working in it right now?

Addition 1:
I mean is there a property that dynamically give me the physical address of a form or usercontrol, that when I use it, it give me the address written in the box of "Full Path" inside the properties menu, and I could use it like:

VB
Dim myaddress as string = me.FullPath


Addition 2:
In the solution explorer when you select a file such as form or usercontrol or even image file or a foler, after you righ-click on it and select properties, in the properties menu you see a row which includes the full path of that file (Full Path), Now I'm looking for a way to access that property dynamicaly inside the program, like writing
VB
return me.FullPath
and it returns the full path of the file.

What I have tried:

So far I'm reading the MSDN and trying to find a property that gives me the physical address of the usercontrol or a form.
Posted
Updated 27-Jul-16 1:01am
v3
Comments
[no name] 27-Jul-16 3:17am    
No, there is not a physical address available. What will you do? Do you Need somthing like "MyForm/MyPanel/MyUserControl" where "My..." are the names of the controls?
m.r.m.40 27-Jul-16 3:24am    
No, I need something like "C:\application\Accounting\Form1".
[no name] 27-Jul-16 3:28am    
I don't get it :)
m.r.m.40 27-Jul-16 3:34am    
I updated the question, the addition 2 is posted in response to you.
Richard MacCutchan 27-Jul-16 3:30am    
Forms do not have physical addresses, they are dynamic objects created at run time, from various pieces of program logic.

Not sure whether this does match your request and also whether it is a good idea for production.
Anyway maybe you try it and get some ideas.

Use System.Runtime.CompilerServices for this:
C#
using System.Runtime.CompilerServices;

namespace LogTests
{
    public static class LogTest
    {
        public static string Log(string infoText,
                                [CallerFilePath] string file = "",
                                [CallerMemberName] string member = "",
                                [CallerLineNumber] int line = 0)
        {
            string test = string.Format("File= {0} Member= {1} Line= {2} InfoText= {3}", file, member, line, infoText);
            return (test);
        }
    }
}


MyControl has do do something like this:
C#
namespace MyControls
{
    public class MyControl
    {
        // ...
        private void PathTest()
        {
            string test = LogTest.Log("MyControl");
        }
        // ....
    }
}


I hope it helps.
 
Share this answer
 
If I understood the question right the answer is : Reflection.
With the code below you could search inside your Application for the required objects and get their name.

VB
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
        Dim t() As Type = a.GetTypes()

        For Each ty As Type In t
            If ty.BaseType.Name = "Form" Then
                MessageBox.Show(ty.Name)
            End If
        Next

    End Sub
End Class


Also with Reflection you can get the Properties of a specified Object-Type - but not in the way you think.
To complete this you should provide much more Information ... what is your final Goal ?
 
Share this answer
 
Use
C#
Server.MapPath
or
XML
Path.GetFullPath
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900