GoldenJag
asked on
Filestream Reference
With this snipplet of code. What do i need to reference in C# to get this to work? Or what am i doing wrong?
i get the following errors:
1. System.EventArgs' does not contain a definition for 'Message'
2. A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else
3. Cannot create an instance of the abstract class or interface 'System.IO.Stream'
I have the following already referenced:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls ;
using System.Data.SqlClient;
using System.IO;
int fileid = Convert.ToInt32(DataGrid1. SelectedIt em.Cells[1 ].Text);
com.solutions.webservices. Crypt ws = new com.solutions.webservices. Crypt();
byte[] test = ws.DecryptStoredFile(pm.se ssionKey,f ileid);
string FileName = Path.GetTempFileName();
FileStream File_Stream = new FileStream(FileName, FileMode.Append, FileAccess.Write);
StreamWriter FileWriter = new Stream(File_Stream);
try
{
FileWriter.BaseStream.Seek (0, SeekOrigin.End);
FileWriter.WriteLine(test) ;
}
catch(Exception e)
{
Response.Write(e.Message.T oString()) ;
}
finally
{
FileWriter.Close();
}
i get the following errors:
1. System.EventArgs' does not contain a definition for 'Message'
2. A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else
3. Cannot create an instance of the abstract class or interface 'System.IO.Stream'
I have the following already referenced:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls
using System.Data.SqlClient;
using System.IO;
int fileid = Convert.ToInt32(DataGrid1.
com.solutions.webservices.
byte[] test = ws.DecryptStoredFile(pm.se
string FileName = Path.GetTempFileName();
FileStream File_Stream = new FileStream(FileName, FileMode.Append, FileAccess.Write);
StreamWriter FileWriter = new Stream(File_Stream);
try
{
FileWriter.BaseStream.Seek
FileWriter.WriteLine(test)
}
catch(Exception e)
{
Response.Write(e.Message.T
}
finally
{
FileWriter.Close();
}
If your code is part of an event handler then e.Message is causing a conflict with "EventArgs e" in the event arguments. Try changing to:
catch (Exception ex)
{
Response.Write(ex.Message. ToString() );
}
catch (Exception ex)
{
Response.Write(ex.Message.
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks carl tawn!! that got rid of errors 1 and 2. Any clue on what to do for error number 3?
See previous post :o)
ASKER
Thanks!
ASKER
error number 1 comes from this snipplet of code: Response.Write(e.Message.T
error number 2 comes from this snipplet: catch(Exception e)
error number 3 comes from this snipplet: StreamWriter FileWriter = new Stream(File_Stream); // new is underlined
Error number 3 is my main concern.