public void ImageStored(Object sender,EventArgs e)
{
Stream imgdatastream = File1.PostedFile.InputStream;
int imgdatalen = File1.PostedFile.ContentLength;
string imgtype = File1.PostedFile.ContentType;
string imgtitle = TextBox1.Text;
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream.Read(imgdata,0,imgdatalen);
//string connstr="server=(local);database=ImageStore;Trusted_Connection=yes";
SqlConnection connection = new SqlConnection(CWMis.FinanceApp.Base.strConnection);
//SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("INSERT INTO ImgStore(imgtitle,imgtype,imgdata)VALUES ( @imgtitle, @imgtype,@imgdata )", connection );
SqlParameter paramTitle = new SqlParameter("@imgtitle", SqlDbType.VarChar,50 );
paramTitle.Value = imgtitle;
command.Parameters.Add( paramTitle);
SqlParameter paramData = new SqlParameter( "@imgdata", SqlDbType.Image );
paramData.Value = imgdata;
command.Parameters.Add( paramData );
SqlParameter paramType = new SqlParameter( "@imgtype", SqlDbType.VarChar,50 );
paramType.Value = imgtype;
command.Parameters.Add( paramType );
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
}
这段代码中 我要把openFileDialog读取的文件的 (文件名,文件类型,)INSERT 到数据库中相应的表中,其中文件名为带路径的一串字符,如何只取其文件的名字不要路径,同时如何获取文件的类型,比如DOC;PPT;等~