Hello, I am working on a seemingly unique file uploading project where files that are dropped onto a server are programmatically uploaded to an ms access db (don’t ask, I’m already pushin for sql) I believe the problem lies in converting the ftp stream to binary and then to the db. The intellisense in MS visual Studios seems to like the code, but when I run it I get a “THIS PROPERTY IS NOT SUPPORTED BY THIS CLASS” I’m a little on the new side to C#, here what I’ve put together so far from a compilation of trial and error via googling:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.OleDb;
using System.IO;
using System.Net;
public partial class _Default : System.Web.UI.Page
{
String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/db1.mdb");
OleDbConnection myAccessConnection;
protected void openAccessConnection()
{
if(myAccessConnection.State == ConnectionState.Closed)
{
myAccessConnection.Open();
}
}
protected void closeAccessConnection()
{
if (myAccessConnection.State == ConnectionState.Open)
{
myAccessConnection.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
myAccessConnection = new OleDbConnection(connStr);
if (!IsPostBack)
{
displayImages();
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
string fileInf = "";
string ImageType = "";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftplocation.com/example.tif");
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential("**UN**", "**PW**");
request.UseBinary = true;
request.ContentLength = fileInf.Length;
int ImageSize;
Stream ImageStream;
ImageSize = fileInf.Length;
ImageType = request.ContentType;
ImageStream = request.GetRequestStream();
byte[] ImageContent = new byte[ImageSize];
int IntStatus;
IntStatus = ImageStream.Read(ImageContent, 0, ImageSize);
OleDbCommand myCommand = new OleDbCommand("insert into tblImg(img_title,img_stream,img_type) values(@img_title,@img_stream,@img_type)", myAccessConnection);
myCommand.CommandType = CommandType.Text;
OleDbParameter img_title = new OleDbParameter("@img_title", OleDbType.VarChar);
img_title.Value = txtImgTitle.Text;
myCommand.Parameters.Add(img_title);
OleDbParameter img_stream = new OleDbParameter("@img_stream", OleDbType.Binary);
img_stream.Value = ImageContent;
myCommand.Parameters.Add(img_stream);
OleDbParameter img_Type = new OleDbParameter("@img_type", OleDbType.VarChar);
img_Type.Value = ImageType;
myCommand.Parameters.Add(img_Type);
try
{
openAccessConnection();
myCommand.ExecuteNonQuery();
closeAccessConnection();
Response.Redirect("_default.aspx");
}
catch (Exception exc)
{
Response.Write("Insert Failure. Error Details : " + exc.Message.ToString());
}
}
public void displayImages()
{
try
{
openAccessConnection();
OleDbCommand myCommand = new OleDbCommand("select * from tblImg", myAccessConnection);
myCommand.CommandType = CommandType.Text;
OleDbDataAdapter myAdapter = new OleDbDataAdapter(myCommand);
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet);
if (myDataSet.Tables[0].Rows.Count>0)
{
GridView1.DataSource = myDataSet;
GridView1.DataBind();
}
closeAccessConnection();
}
catch (Exception exc)
{
Response.Write("Error Details : " + exc.Message.ToString());
}
}
public string imageURL(string img_id)
{
return ("retrieveImages.aspx?id=" + img_id);
}
}
Any assistance would be greatly appreciated.