Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Thursday, March 22, 2012

Server.Execute sluggish, faster way to retrieve HTML string?

Hi,

I need to retrieve the HTML string of one of my ASP pages, and whenever I make the attempt using my code, it brings the entire server to a hault for quite a while. The server's hardware specs are perfectly fine, and I've narrowed it down to the Server.Execute line. Is there anything I can do here? Here's my code:

StringWriter sw =new StringWriter();Server.Execute("page.aspx", sw);String strHtmlCode = sw.GetStringBuilder().ToString();

Thanks!

Use HttpWebRequest/HttpWebResponse:

//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}

String strHtmlCode = GetHtmlPage("http://domain/page.aspx");


This may be because page.aspx may be huge page and it will take long time in processing. Because of this, your current page execution will stop:)

Cheers

Bhavesh


lad.bhavesh:

This may be because page.aspx maybe huge page and it will take long time in processing. Because of this,your current page execution will stop:)

Cheers

Bhavesh


Including the one image and stylesheet, it's about 55 KB.


Mikesdotnetting:

Use HttpWebRequest/HttpWebResponse:

//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}

String strHtmlCode = GetHtmlPage("http://domain/page.aspx");

I apologize - I should have been more clear on the context here. A session needs to be maintained in order to access this page. Is there anything else I can use? And believe me, I've tried googling :). I'm sure it's out there somewhere, but I can't seem to find it.

Will this do you?

http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx


That'll do it, thanks!

Server.HTMLDecode doesn't decode char 345

Hello!
I have a problem decoding the czech character:
r
The HTML code for this character is ř but when running
Server.HTMLdecode on that string it just returns ř instead of the real
char. (It works on a lot of other characters)
I need to decode this string in order to render an image with this character
as a part of a headline.
Can anyone help me with this issue, or is it maybe a bug?
/kindest regards, JonasThis works fine for me:
Response.Write(Server.HtmlDecode("ř"));
My web.config specifies:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
maybe yours is using something else?
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
> Hello!
> I have a problem decoding the czech character:
> r
> The HTML code for this character is ř but when running
> Server.HTMLdecode on that string it just returns ř instead of the
> real char. (It works on a lot of other characters)
> I need to decode this string in order to render an image with this
> character as a part of a headline.
> Can anyone help me with this issue, or is it maybe a bug?
> /kindest regards, Jonas
>
Maybe it is because I'm usning the Server object in a function in a non web
environment - a regular class:
string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
text );
where the text property sometimes contains the char ř
Is there some way that I can tell the HtmlDecode which encoding to use?
/Jonas
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>
i don't think that's your problem (although within a class, there's no
reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
class from the context (ie, it can be reused outside of the web)).
All HtmlDecode does in the case of a numeric value (such as 345), is:
char c1 = (char) ((ushort) int.Parse("345"));
Response.Write(c1);
Is your page encoding set to utf-8? (if you put tracing on, at the top of
the trace information it says the encoding).l
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
> Maybe it is because I'm usning the Server object in a function in a non
> web environment - a regular class:
> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
> text );
> where the text property sometimes contains the char ř
> Is there some way that I can tell the HtmlDecode which encoding to use?
> /Jonas
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>
Yes the encoding is set ut utf-8
the strange thing is that the decodedText property still contains the
"ř" string after HtmlDecode
Nevermind, thanks for your explanation of the HtmlDecode, I have now created
a SpecialDecode function instead that works fine
private static string SpecialDecode(string decodedText)
{
string tmpResult = decodedText;
bool found = true;
try
{
while(found)
{
if( tmpResult.IndexOf("&#") > -1 )
{
string chars = tmpResult.Substring( tmpResult.IndexOf("&#")+2, 3);
//decode
char c1 = (char) ((ushort) int.Parse(chars));
tmpResult = tmpResult.Replace("&#" + chars + ";", c1.ToString());
}
else
{
found = false;
}
}
}
catch{}
return tmpResult;
}
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e2uGEB2lFHA.3936@.TK2MSFTNGP10.phx.gbl...
>i don't think that's your problem (although within a class, there's no
>reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
>class from the context (ie, it can be reused outside of the web)).
> All HtmlDecode does in the case of a numeric value (such as 345), is:
> char c1 = (char) ((ushort) int.Parse("345"));
> Response.Write(c1);
> Is your page encoding set to utf-8? (if you put tracing on, at the top of
> the trace information it says the encoding).l
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
>
Karl Seguin wrote:

> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
Numeric references are based on Unicode code points, thus
requestEncoding and responseEncoding don't apply.
Cheers,
--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Server.HTMLDecode doesnt decode char 345

Hello!

I have a problem decoding the czech character:
r

The HTML code for this character is ř but when running
Server.HTMLdecode on that string it just returns ř instead of the real
char. (It works on a lot of other characters)
I need to decode this string in order to render an image with this character
as a part of a headline.

Can anyone help me with this issue, or is it maybe a bug?

/kindest regards, JonasThis works fine for me:
Response.Write(Server.HtmlDecode("ř"));

My web.config specifies:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" /
maybe yours is using something else?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
> Hello!
> I have a problem decoding the czech character:
> r
> The HTML code for this character is ř but when running
> Server.HTMLdecode on that string it just returns ř instead of the
> real char. (It works on a lot of other characters)
> I need to decode this string in order to render an image with this
> character as a part of a headline.
> Can anyone help me with this issue, or is it maybe a bug?
> /kindest regards, Jonas
Maybe it is because I'm usning the Server object in a function in a non web
environment - a regular class:

string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
text );

where the text property sometimes contains the char ř

Is there some way that I can tell the HtmlDecode which encoding to use?

/Jonas

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>> Hello!
>>
>> I have a problem decoding the czech character:
>> r
>>
>> The HTML code for this character is ř but when running
>> Server.HTMLdecode on that string it just returns ř instead of the
>> real char. (It works on a lot of other characters)
>> I need to decode this string in order to render an image with this
>> character as a part of a headline.
>>
>> Can anyone help me with this issue, or is it maybe a bug?
>>
>> /kindest regards, Jonas
>>
i don't think that's your problem (although within a class, there's no
reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
class from the context (ie, it can be reused outside of the web)).

All HtmlDecode does in the case of a numeric value (such as 345), is:

char c1 = (char) ((ushort) int.Parse("345"));
Response.Write(c1);

Is your page encoding set to utf-8? (if you put tracing on, at the top of
the trace information it says the encoding).l

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
> Maybe it is because I'm usning the Server object in a function in a non
> web environment - a regular class:
> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
> text );
> where the text property sometimes contains the char ř
> Is there some way that I can tell the HtmlDecode which encoding to use?
> /Jonas
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>> This works fine for me:
>> Response.Write(Server.HtmlDecode("ř"));
>>
>> My web.config specifies:
>> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
>>
>> maybe yours is using something else?
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/ - New and Improved (yes, the popup is
>> annoying)
>> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
>> come!)
>>
>>
>> "Jonas kermark" <jonas@.wipcore.se> wrote in message
>> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>>> Hello!
>>>
>>> I have a problem decoding the czech character:
>>> r
>>>
>>> The HTML code for this character is ř but when running
>>> Server.HTMLdecode on that string it just returns ř instead of the
>>> real char. (It works on a lot of other characters)
>>> I need to decode this string in order to render an image with this
>>> character as a part of a headline.
>>>
>>> Can anyone help me with this issue, or is it maybe a bug?
>>>
>>> /kindest regards, Jonas
>>>
>>
>>
Yes the encoding is set ut utf-8

the strange thing is that the decodedText property still contains the
"ř" string after HtmlDecode

Nevermind, thanks for your explanation of the HtmlDecode, I have now created
a SpecialDecode function instead that works fine

private static string SpecialDecode(string decodedText)
{
string tmpResult = decodedText;
bool found = true;
try
{
while(found)
{
if( tmpResult.IndexOf("&#") > -1 )
{
string chars = tmpResult.Substring( tmpResult.IndexOf("&#")+2, 3);
//decode
char c1 = (char) ((ushort) int.Parse(chars));
tmpResult = tmpResult.Replace("&#" + chars + ";", c1.ToString());
}
else
{
found = false;
}
}
}
catch{}

return tmpResult;
}

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e2uGEB2lFHA.3936@.TK2MSFTNGP10.phx.gbl...
>i don't think that's your problem (although within a class, there's no
>reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
>class from the context (ie, it can be reused outside of the web)).
> All HtmlDecode does in the case of a numeric value (such as 345), is:
> char c1 = (char) ((ushort) int.Parse("345"));
> Response.Write(c1);
> Is your page encoding set to utf-8? (if you put tracing on, at the top of
> the trace information it says the encoding).l
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
>> Maybe it is because I'm usning the Server object in a function in a non
>> web environment - a regular class:
>>
>> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
>> text );
>>
>> where the text property sometimes contains the char ř
>>
>> Is there some way that I can tell the HtmlDecode which encoding to use?
>>
>> /Jonas
>>
>> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>>> This works fine for me:
>>> Response.Write(Server.HtmlDecode("ř"));
>>>
>>> My web.config specifies:
>>> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
>>>
>>> maybe yours is using something else?
>>>
>>> Karl
>>>
>>> --
>>> MY ASP.Net tutorials
>>> http://www.openmymind.net/ - New and Improved (yes, the popup is
>>> annoying)
>>> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
>>> come!)
>>>
>>>
>>> "Jonas kermark" <jonas@.wipcore.se> wrote in message
>>> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>>>> Hello!
>>>>
>>>> I have a problem decoding the czech character:
>>>> r
>>>>
>>>> The HTML code for this character is ř but when running
>>>> Server.HTMLdecode on that string it just returns ř instead of the
>>>> real char. (It works on a lot of other characters)
>>>> I need to decode this string in order to render an image with this
>>>> character as a part of a headline.
>>>>
>>>> Can anyone help me with this issue, or is it maybe a bug?
>>>>
>>>> /kindest regards, Jonas
>>>>
>>>
>>>
>>
>>
Karl Seguin wrote:

> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl

Numeric references are based on Unicode code points, thus
requestEncoding and responseEncoding don't apply.

Cheers,
--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Server.HTMLEncode

Hi,
The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]
---
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".
[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
---
However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."
Am I missing something? Am I not using the correct encoding method?
Any assistance gratefully received.
Best,
Mark RaeHi,
Use Server.UrlEncode for the output you are expecting.
"Mark Rae" <mark@.mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:eBm3iJ$cEHA.592@.TK2MSFTNGP11.phx.gbl...
Hi,
The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]
---
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".
[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
---
However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."
Am I missing something? Am I not using the correct encoding method?
Any assistance gratefully received.
Best,
Mark Rae
Mark Rae wrote:

> Hi,
> The following is lifted straight from the MSDN help topic for
> HttpServerUtility.HtmlEncode Method [C#]
> ---
> The following example encodes a string for transmission by HTTP. It encode
s
> the string named TestString, which contains the text "This is a <Test
> String>.", and copies it into the string named EncodedString as
> "This+is+a+%3cTest+String%3e.".
> [C#]
> String TestString = "This is a <Test String>.";
> StringWriter writer = new StringWriter();
> Server.HtmlEncode(TestString, writer);
> String EncodedString = writer.ToString();
> ---
> However, when I run it, the value of EncodedString is "This is a <Test
> String>." not "This+is+a+%3cTest+String%3e."
> Am I missing something? Am I not using the correct encoding method?
> Any assistance gratefully received.
> Best,
> Mark Rae
>
Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
would be expected to.
-Mike
"Mike Newton" <MNewton@.Addus.com> wrote in message
news:ewkETQ$cEHA.2236@.TK2MSFTNGP10.phx.gbl...
Mike & Silva,

> Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
> would be expected to.
Thanks very much. Is the MSDN topic wrong, then...?

Server.HtmlEncode DataBinder

Thanks - I tried the + and got this error message:
Conversion from string "pageview.aspx?tab=1&catid=1" to type 'Double'
is not valid.'<%#"/pageview.aspx?tab=1&catid="+DataBinder.Eval(Container.DataItem,"CAT_ID
")%>'
"Fossie" <gillmcd@.ihug.co.nz> wrote in message
news:1148112901.230750.47520@.j73g2000cwa.googlegroups.com...
> Thanks - I tried the + and got this error message:
> Conversion from string "pageview.aspx?tab=1&catid=1" to type 'Double'
> is not valid.
>
<asp:HyperLink id="hyperlinkk1" Runat="server"
NavigateUrl='<%#"/pageview.aspx?tab=1&catid="+DataBinder.Eval(Container.Data
Item,"CAT_ID")%>'</asp:HyperLink>
"Fossie" <gillmcd@.ihug.co.nz> wrote in message
news:1148112901.230750.47520@.j73g2000cwa.googlegroups.com...
> Thanks - I tried the + and got this error message:
> Conversion from string "pageview.aspx?tab=1&catid=1" to type 'Double'
> is not valid.
>

Tuesday, March 13, 2012

Server.MapPath and ASP.Net

I have this code:

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\unzipped\exceldotnet[1]\exceltest.xls;" & _
"Extended Properties=Excel 8.0;"

which works fine. I have copied the .xls-file to my project folder and tries this code:

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.mappath("exceltest.xls") & ";" & _
"Extended Properties=Excel 8.0;"

But then I receive an error saying:

The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data.

What's wrong, can't I use the server.mappath?Make sure the asp.net account has access to the directory containing the .mdb file.
You're right, I'd forgot! Thanks ;)
Hi again, I have problems with Server.MapPath in a class. The intellisense wouldn't recognize server.mappath. Am I doing something wrong or do I need to specify a namespace? Here is my code:

Imports System.Data
Imports System.Data.OleDb
Public Class clsMedieroer : Inherits clsMateriale
Private _medie As Integer
Private _medie1 As Integer
Private _dimension As Integer

Sub New(ByVal s As Integer, ByVal m As String)
' konstruktren skaber et materiale med s
' (sker ved at kalde klassens metode Medie med s som parameter)
MyBase.New(m)
Medie = s
End Sub

Public Sub FindMedie()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.mappath("exceltest.xls") & ";" & _
"Extended Properties=Excel 8.0;"

Dim strSql As String = "SELECT * FROM [Sheet1$] WHERE Id=4"

Dim objConnection As New OleDbConnection(strConn)
Dim objCommand As New OleDbCommand(strSql, objConnection)
Dim objDataReader As OleDbDataReader

objConnection.Open()
objDataReader = objCommand.ExecuteReader()

Do While objDataReader.Read() = True
_dimension = CInt(objDataReader("pris"))
Loop
objDataReader.Close()
objConnection.Close()

Select Case _medieroer
Case Is = "St. 37.0 Konti"
_medie1 = 15
Case Else
_medie1 = _medie
End Select
End Sub

Public ReadOnly Property Medie1() As Integer
' returnerer vrdien af materialet, der lses fra
Get
Return _medie1
End Get
End Property

Public ReadOnly Property Dimension() As Integer
' returnerer vrdien af materialet, der lses fra
Get
Return _dimension
End Get
End Property

Public WriteOnly Property Medie() As Integer
' definerer vrdien af materialet
Set(ByVal Value As Integer)
_medie = Value
FindMedie()
End Set
End Property

End Class
using System.Web;
I've tried typing
Imports system.web
but it still doesn't work

Server.MapPath >> Path from my web application

Hi,

I would like to get path from my web application :

exemple : C:\InitPub\www\webApplication1\

When I use in my code behind :

string path =ClassXml.GetValueFromKeyGeneric( Server.MapPath("XML/XMLFile_Config.xml"),"/configs/configs","PATHWEBSITE");

it's work,

But when I use this in my class in App_Code , I have this mistake : Error 115 The name 'Server' does not exist in the current context

Since your class does not derive from System.Web.UI.Page, it does nothave access to the 'Server' shortcut. UseSystem.Web.HttpContext.Current.Server.MapPath() instead.

When I useSystem.Web.HttpContext.Current.Server.MapPath(".")

I have this message :
Compiler Error Message:CS0134: 'ClassConstante.PATHNOVAGATE' is of type 'string.' A const of reference type other than string can only be initialized with null


Hello,

I change my string by :

string path = System.Web.HttpContext.Current.Server.MapPath("Default.aspx");

But I have always errors :

{"Object reference not set to an instance of an object."}


is Default.aspx in the same folder as the call? Try with a "." instead once, and see what folder it gives you...

Server.MapPath and web.config

Hi All
I have a 'small' problem. :sick:

Is there any way to use Server.mapPath in the web.config when specifying the connection string for my database?
I have been able to use it in my webforms but want to keep it stored in one place, namely the web.config file.

Unfortunately, I am getting errors when I try to use "&" when constructing my connectionstring using Server.mappath(".")

Has anyone done this before?

I also noticed that Server.mappath is not recognized when I tried to use it in a vb class file, although I am able to use it in the code-behind file of a webform. Any ideas?

ThanksI dont think you can use server.Mappath in the Config file. You will have to hard-code the path of your Access(?) DB there.
To use it in a .vb file you need to write the full namespace, ie.

httpcontext.Current.Server.MapPath()

..or import the namespace.

The web.config file is there to be configured when u set up an application. Thats why it can be modified in a normal text editor. You'll need to specify the full (or relative) path to the access database.
Don't store the phrase Server.Mappath in your web.config. Just store the latter part of the string, which should be concatenated with Server.Mappath in your application.