PC Review


Reply
Thread Tools Rate Thread

ASP.NET C# WriteToFile StreamWriter error: 'StreamWriter' could not be found

 
 
rex64
Guest
Posts: n/a
 
      15th Jun 2005
I am getting an error message and I have not been able to figure hot
how to fix it. I have done some research with no answers yet.

I found this code that may help? Not sure what to do with it.
using (StreamWriter sw = new StreamWriter (fullAddress , false,
Encoding.UTF7))


Error message::::::::::::::::::::::::::::::::::::::::::::::
[code]
Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name
'StreamWriter' could not be found (are you missing a using directive or
an assembly reference?)

Source Error:



Line 40:
Line 41:
Line 42: StreamWriter sw = new StreamWriter(arg1, arg2); //This was
commented out????
Line 43: //the line above is where I get the errors either way.
Line 44:


Source File: E:\webapps\finance\gfst\asp\jeffUploadNsave.aspx Line:
42



Code::::::::::::::::::::::::::::::
void WriteToFile(string szData, string szFilePath)
{
//Write to file
StreamWriter sw = new StreamWriter(arg1, arg2); //This was commented
out???? StreamWriter(arg1, arg2);
//the line above is where I get the errors either way.

// Constructor with 2 arguments:
// 1) Path location of file
// 2) Append or Overwrite Data
StreamWriter(@"G:\Inetpub\wwwroot\csf\Tutorials\Exec\fileIO.txt",true);

//This will append the given input to the file since arg2 is true
sw.Write("I love C# and I don't care who knows it!~~" + "<br>");

//Cleanup
sw.Close();
}

 
Reply With Quote
 
 
 
 
=?Utf-8?B?cGFnYXRlcw==?=
Guest
Posts: n/a
 
      15th Jun 2005
StreamWriter is part of System.IO, so you need a reference to it.

Try putting

using System.IO;

at the top of your code.

HTH,
pagates


"rex64" wrote:

> I am getting an error message and I have not been able to figure hot
> how to fix it. I have done some research with no answers yet.
>
> I found this code that may help? Not sure what to do with it.
> using (StreamWriter sw = new StreamWriter (fullAddress , false,
> Encoding.UTF7))
>
>
> Error message::::::::::::::::::::::::::::::::::::::::::::::
> [code]
> Compilation Error
> Description: An error occurred during the compilation of a resource
> required to service this request. Please review the following specific
> error details and modify your source code appropriately.
>
> Compiler Error Message: CS0246: The type or namespace name
> 'StreamWriter' could not be found (are you missing a using directive or
> an assembly reference?)
>
> Source Error:
>
>
>
> Line 40:
> Line 41:
> Line 42: StreamWriter sw = new StreamWriter(arg1, arg2); //This was
> commented out????
> Line 43: //the line above is where I get the errors either way.
> Line 44:
>
>
> Source File: E:\webapps\finance\gfst\asp\jeffUploadNsave.aspx Line:
> 42
>
>
>
> Code::::::::::::::::::::::::::::::
> void WriteToFile(string szData, string szFilePath)
> {
> //Write to file
> StreamWriter sw = new StreamWriter(arg1, arg2); //This was commented
> out???? StreamWriter(arg1, arg2);
> //the line above is where I get the errors either way.
>
> // Constructor with 2 arguments:
> // 1) Path location of file
> // 2) Append or Overwrite Data
> StreamWriter(@"G:\Inetpub\wwwroot\csf\Tutorials\Exec\fileIO.txt",true);
>
> //This will append the given input to the file since arg2 is true
> sw.Write("I love C# and I don't care who knows it!~~" + "<br>");
>
> //Cleanup
> sw.Close();
> }
>
>

 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      15th Jun 2005
rex64,

The reason for this is that you are using the shorthand for the
StreamWriter class, and you don't have the appropriate imports statement at
the top. What you want to do is place this at the top of your page:

<%@ Import namespace="System.IO" %>

And it should work.

Hope this helps.

--

- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)


"rex64" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am getting an error message and I have not been able to figure hot
> how to fix it. I have done some research with no answers yet.
>
> I found this code that may help? Not sure what to do with it.
> using (StreamWriter sw = new StreamWriter (fullAddress , false,
> Encoding.UTF7))
>
>
> Error message::::::::::::::::::::::::::::::::::::::::::::::
> [code]
> Compilation Error
> Description: An error occurred during the compilation of a resource
> required to service this request. Please review the following specific
> error details and modify your source code appropriately.
>
> Compiler Error Message: CS0246: The type or namespace name
> 'StreamWriter' could not be found (are you missing a using directive or
> an assembly reference?)
>
> Source Error:
>
>
>
> Line 40:
> Line 41:
> Line 42: StreamWriter sw = new StreamWriter(arg1, arg2); //This was
> commented out????
> Line 43: //the line above is where I get the errors either way.
> Line 44:
>
>
> Source File: E:\webapps\finance\gfst\asp\jeffUploadNsave.aspx Line:
> 42
>
>
>
> Code::::::::::::::::::::::::::::::
> void WriteToFile(string szData, string szFilePath)
> {
> //Write to file
> StreamWriter sw = new StreamWriter(arg1, arg2); //This was commented
> out???? StreamWriter(arg1, arg2);
> //the line above is where I get the errors either way.
>
> // Constructor with 2 arguments:
> // 1) Path location of file
> // 2) Append or Overwrite Data
> StreamWriter(@"G:\Inetpub\wwwroot\csf\Tutorials\Exec\fileIO.txt",true);
>
> //This will append the given input to the file since arg2 is true
> sw.Write("I love C# and I don't care who knows it!~~" + "<br>");
>
> //Cleanup
> sw.Close();
> }
>



 
Reply With Quote
 
rex64
Guest
Posts: n/a
 
      15th Jun 2005
That did not work:
Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1519: Invalid token 'using' in class, struct,
or interface member declaration

Source Error:



Line 6: <body bgcolor="#ffffff" style="font:8pt verdana;">
Line 7: <script language="C#" runat="server">
Line 8: using System.IO;
Line 9: //Strings:
http://www.peachpit.com/articles/art...1938&seqNum=12
Line 10: //http://www.developerfusion.com/show/4398/

 
Reply With Quote
 
rex64
Guest
Posts: n/a
 
      15th Jun 2005
That worked. I put it at the very top above the C# declartation. Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
difference in Filestream + StreamWriter and just StreamWriter =?Utf-8?B?aXdkdTE1?= Microsoft VB .NET 1 2nd Aug 2006 01:40 PM
if System.IO.StreamWriter write throws an exception, is there anyway to close the System.IO.StreamWriter object? it seems to stay open when this happens then future attempts to write to that same path fail because it says its in use by another proces Daniel Microsoft Dot NET 3 8th Sep 2005 06:47 PM
if System.IO.StreamWriter write throws an exception, is there anyway to close the System.IO.StreamWriter object? it seems to stay open when this happens then future attempts to write to that same path fail because it says its in use by another proces Daniel Microsoft C# .NET 3 8th Sep 2005 03:07 PM
if System.IO.StreamWriter write throws an exception, is there anyway to close the System.IO.StreamWriter object? it seems to stay open when this happens then future attempts to write to that same path fail because it says its in use by another proces Daniel Microsoft Dot NET Framework 0 8th Sep 2005 01:40 AM
capture using(StreamWriter wr = new StreamWriter()) exceptional kids_pro Microsoft C# .NET 6 3rd Sep 2004 07:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:28 AM.