שתף באמצעות


HOw to get the application root directory path

Question

Sunday, October 3, 2010 12:36 PM

Hi

here i am getting this path

System.Windows.Forms.Application.StartupPath
"D:\Projects\Compan1\Compan1bin\Debug"

but i want to load report1.rpt  that is reside in Reports folder under application root

like we did in asp.net application

  Dim rptPath As String = Server.MapPath("~/Reports/rpt1.rpt")

  If ds.Tables(0).Rows.Count > 0 Then
                        'Report.Load(System.Windows.Forms.Application.StartupPath & "/Reports/" & ReportName & "")

                        Report.SetDataSource(ds)
                        CrystalReportViewer.ReportSource = Report
                        Me.Panel1.Controls.Add(CrystalReportViewer)
end if

adil

All replies (14)

Sunday, October 3, 2010 3:55 PM ✅Answered | 1 vote

dim newdir as string=System.Windows.Forms.Application.StartupPath + "\Report\rpt1.rpt"

Renee


Sunday, October 3, 2010 3:59 PM ✅Answered | 1 vote

Sorry, this is better:

 

dim rptPath = Path.Combine(Application.StartupPath, "Reports\rpt1.rpt");

--
Mike


Sunday, October 3, 2010 3:57 PM

You can use Path.Combine, as in:

 

    dim rptPath = Path.Combine(Application.StartupPath, "Reports/rpt1.rpt");

--
Mike


Sunday, October 3, 2010 4:16 PM

Sorry, this is better:

 

dim rptPath = Path.Combine(Application.StartupPath, "Reports\rpt1.rpt");

--
Mike

No also not, that semicolon gives an error in VB

:-)

I've still not decided for myself if I find the use of the Combine function better in VB than using the Concatenation operator, C# misses in fact that operator  the & in VB makes it a very clear if it is used.

I became curious, but see now that C# has the same problem in version 4 as VB with option Strict off if the + is used to concatinate.

dynamic c = 1 +"2";

Result "12" no error.

I know this is out of order it is a VB forum.

 

Success
Cor


Sunday, October 3, 2010 4:57 PM

Cor,

It's still educational....

Renee


Sunday, October 3, 2010 5:04 PM

Hi Cor,

I reckon the "+" symbol should be made to throw an exception error when used to concatenate strings.

That would make people think about what they are doing.  ;-)    :-)    :-D

 

Regards, John

www.johnaoliver.com


Sunday, October 3, 2010 5:07 PM

Better as far as what is concerned? CPU time? Flexibility? Syntax? What?

Renee


Sunday, October 3, 2010 5:13 PM

Better as far as what is concerned? CPU time? Flexibility? Syntax? What?

Renee

Hi Renee,

It would, in the long term, produce better code from people who write code of all ages,

that is if the compiler saw the "+" symbol as an error instead when used between strings, what do you think?

You could of course argue the "+" is a bonus when used between strings? I personally, do not see it that way.

 

 

Regards, John

www.johnaoliver.com


Sunday, October 3, 2010 6:03 PM

Sorry, I meant only better in terms of my first post had "Reports/rpt1.rpt", and my second had "Reports\rpt1.rpt".

 

In other words, I meant no disrespect to your answer.  I posted mine within moments of your post, and had not seen yours.  My preference though is to use Path.Combine where possible.

--
Mike


Sunday, October 3, 2010 7:03 PM

Hi Mike,

Mine isn't. I don't use VB specifics especially if they are invogue or make things "easier". A + sign is ok with and an "&" sign is not as it's far too "VB" for me.

John, nah...I'd rather be able to use the + sign rather than the ampersand any day.

Renee

 


Sunday, October 3, 2010 8:32 PM

I guess I am really confused, as I never wrote anything about "a" + "b" versus "a" & "b".  In vb.net, I would always use "a" & "b".

--
Mike


Sunday, October 3, 2010 9:23 PM

Mike,

The first paragraph was a paragraph to you. No, you didn't write anything on the +. I used it as an example.

The second and last paragraph was to John.

Renee


Sunday, October 3, 2010 9:32 PM

I guess the vb specific thing threw me, as Path.Combine is not a vb specific thing, but then you wrote the + vs & stuff.

--
Mike


Monday, October 4, 2010 6:42 AM

@Renee,

Better is for me always related too maintainability. 

My expirience is that if a program is easy to maintain, it runs mostly also the best.

(Watch the word mostly, there are sometimes exceptions on that rule)

@John

The + sign in VB for concatination throws an error in VB with Option Strict On if wrongly used

@Mike

I wrote my Text about the concationation character because we see in my idea the combine used by C# developers than in VB developers. My idea about it was because C# lacks the concatination operator. By showing the semicolon at the end of your sample. You showed also that you use beside VB also C#.

:-)

Success
Cor