Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text file which includes some html code to populate html formatted content as the text of an asp:label (<asp:label>). The reading of the text file itself goes just fine ;however, this only occurs when I use an absolute file path which will not work of course once I upload the website to a hosting service. The text file is in the same directory as both the .aspx file and the codebehind the page file in the Website directory in the Visual Studio 2005 directory structure located in "My Documents". Here is the error message that I receive when I attempt to create load the page without an absolute file path to the text file in the StreamReader object: - Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Default4.txt'.
-
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
-
-
Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Default4.txt'.
-
-
Source Error:
-
-
Line 17: protected void Page_Load(object sender, EventArgs e)
-
Line 18: {
-
Line 19: StreamReader cr = new StreamReader("Default4.txt");
-
Line 20: string contents = null;
-
Line 21: contents = cr.ReadToEnd();
-
-
-
Source File: c:\Documents and Settings\Main\My Documents\Visual Studio 2005\WebSites\WebSite2\Default4.aspx.cs Line: 19
-
-
Stack Trace:
-
-
[FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Default4.txt'.]
-
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +1971213
-
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998
-
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) +115
-
System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) +85
-
System.IO.StreamReader..ctor(String path) +112
-
_Default.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Main\My Documents\Visual Studio 2005\WebSites\WebSite2\Default4.aspx.cs:19
-
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
-
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
-
System.Web.UI.Control.OnLoad(EventArgs e) +80
-
System.Web.UI.Control.LoadRecursive() +49
-
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3745
-
-
-
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
Here is the code for the C# code behind the page file: - using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Web.UI.HtmlControls;
-
using System.IO;
-
-
/// <summary>
-
/// Summary description for Default4
-
/// </summary>
-
public partial class _Default : System.Web.UI.Page
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
StreamReader cr = new StreamReader("Default4.txt");
-
string contents = null;
-
contents = cr.ReadToEnd();
-
Label1.Text = contents;
-
cr.Close();
-
//Label1.Text = "<p align=center>Hello World</p>";
-
}
-
-
}
-
Here is the Code to the .aspx file: - <%@ Page Language="C#" AutoEventWireup="true" CodeFile="~/Default4.aspx.cs" Inherits="_Default"%>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<script runat="server">
-
-
</script>
-
-
<html xmlns="http://www.w3.org/1999/xhtml" >
-
<head runat="server">
-
<style type="text/css">
-
.staticMenuItem
-
{
-
color:White;
-
-
font-weight: bold;
-
text-align: center;
-
-
/*border:solid 1px black;
-
padding:2px 4px;*/
-
}
-
.menuHover
-
{
-
color:#ffcc00;
-
background-color:#ff3300;
-
}
-
.dmenuHover
-
{
-
color:blue;
-
background-color:#ff9900;
-
}
-
.dynamicMenuItem
-
{
-
color:white;
-
font-weight: bold;
-
text-align: center;
-
/*background-color:#FF6600;*/
-
padding:2px 4px;
-
}
-
.dynamicMenu
-
{
-
/*the background color for the dynamic menus both "popout" and non is covered by the
-
DynamicMenuStyle-BackColor="#FF6600" in the <asp:Menu> tag*/
-
/*background-color: #ffcc00;*/
-
/*background-color: green;*/
-
/*font-weight: bold;
-
text-align: center;*/
-
/*border:Solid 1px black;
-
filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=5, OffY=5, Color='gray', Positive='true')" ;*/
-
}
-
</style>
-
<title>Untitled Page</title>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
-
<asp:Menu ID="Menu1" runat="server" BackColor="#990000" DynamicMenuStyle-BackColor="#333333" DataSourceID="SiteMapDataSource1" StaticDisplayLevels="2"
-
StaticMenuItemStyle-CssClass="staticMenuItem"
-
StaticHoverStyle-CssClass="menuHover"
-
DynamicHoverStyle-CssClass="menuHover"
-
DynamicMenuItemStyle-CssClass="dynamicMenuItem"
-
DynamicMenuStyle-CssClass="dynamicMenu">
-
<StaticMenuItemStyle ItemSpacing="20px" />
-
<DynamicMenuItemStyle ItemSpacing="0px" />
-
</asp:Menu>
-
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
-
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
-
-
</div>
-
</form>
-
</body>
-
</html>
-
Here is the code located in the text file named Default4.txt: - <br /><p align=right>Hello There World!!</p>
And finally here is the file path that I must use in the StreamReader object in order to avoid generating an error: - C:\\Documents and Settings\\Main\\My Documents\\Visual Studio 2005\\WebSites\\WebSite2\\
Is what is going on unfixable? Also could someone experienced with uploading Visual Web Developer 2005 generated sites give me a few pointers on deploying them? Any help here would be greatly appreciated.
1 2896
While assigning the file name, you have to provide it with the path of the file too.
If you do not, then it will map it from the default path.
What you need to do is to map it from the servers path, so that it will navigate from the application folder.
User server.Mappath to get the desired path. and then supply it to the stream reader.
cheers
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: clintonG |
last post by:
Visual C# 2005 Express Edition is a simple, lightweight, integrated
development environment designed for beginning programmers and
non-professional developers interested in building Windows Forms,
class libraries, and console-based applications. Visual C# 2005 Express
Edition includes many of the same productivity features found in
Visual Studio, all streamlined to fit the needs of the non-professional
Windows developer.
--
<%=...
|
by: Patrick Olurotimi Ige |
last post by:
Hi,
I have VStudio.Net 2003 installed but can i install Visual Web
Developer also on the same PC.
My current .Net Frameork version is 1.1.
Will the Visual Web Developer install ASP.NET 2.0?
And if i do will it affect my other applications?
I want ot build ASP.NET 2.0 apps!!!
|
by: pbishop |
last post by:
Hi,
I'm fairly new to ASP.Net. I have Visual Web Developer 2005 Express.
Except for the default.aspx, whenever I create a new Web form, no code
behind (aspx.vb) page is created. The same thing is happening for
master pages.
I have exited Visual Web Developer 2005 Express and restarted it, and I
have rebooted the PC, but the problem persists.
|
by: Nalaka |
last post by:
Hi,
I suddenly started getting a lot of errors from html validation (some CSS)
so I followed the following instructions to disable it.
If you'd rather not have these types of HTML validation errors show up in
your error-list, you can disable this functionality by selecting the
Tools->Options menu item in VS or Visual Web Developer. Select the
TextEditor->Html->Validation tree option in the left-hand side of the
|
by: Progman |
last post by:
I have Visual Studio 2005 Standard edition.
Is ti the same thing as the Express edition or Standard is more?
| |
by: barry |
last post by:
I had Visual Web Developer Express 2005 and Visual Studio 2005 installed on
my computer.
Realizing that I did not need Visual Web Developer Express 2005 since I had
VS 2005 I removed it.
My question could this be a possible reason that the ASP.NET configuration
tool is not
working in VS 2005 when I am doing web development? What happens is upon
execution
it just brings me back into the same VS design page from where I executed.
|
by: Goofy |
last post by:
I see that the code behind is now a partial class. So where is the code
associated with the server controls declaration etc ?
Is this generated on the fly now, or am I missing something ?
--
Goofy
|
by: cj |
last post by:
I'm getting started writing WEB program in VB2005. I'm been doing
windows apps to date. A friend told me to get Visual Web Developer
Express Edition. But I have Visual Studio Pro 2005 and it says I have
Visual Web Developer in it. I'm just not sure what that is and how to
start it. Any advise?
|
by: cpchan |
last post by:
Hello,
Can I create a Web-based application (not a Web site) with Visual C# 2005
Express ?
Or I have to use Visual Web Developer 2005 Express Edition, choose ASP.NET
and then choose C# ?
Are there any web-sites give me step-by-step Visual C# 2005 Express
Web-based application development ?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |