By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

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

P: n/a
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\Ex ec\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();
}

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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\Ex ec\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();
}

Nov 17 '05 #2

P: n/a
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]
- mv*@spam.guard.caspershouse.com
"rex64" <re****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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\Ex ec\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();
}

Nov 17 '05 #3

P: n/a
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/

Nov 17 '05 #4

P: n/a
That worked. I put it at the very top above the C# declartation. Thanks.

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.