hi , iam using asp.net 2.0 with sql server 2000
in my site if iam using xp operating system all clients are able to upload the pictures but the clients those who are using windows7 and vista the are getting errors can you correct my code
C#
@ WebHandler Language="C#" Class="right7" %>
using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
publicclassright7 : IHttpHandler {
publicvoidProcessRequest (HttpContext context)
{
string branchid = "";
//if(context.Session["branchid"]!=null)if (context.Request.QueryString["branchid"] != null)
branchid = context.Request.QueryString["branchid"];
elsethrownew ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = ShowImage(branchid);
byte[] buffer = newbyte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
//context.Response.BinaryWrite(buffer)
}
public Stream ShowImage(string branchid)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["transfer"].ConnectionString);
string sql = "SELECT imgright7 FROM tblImages WHERE BranchId = @BranchId";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@BranchId", branchid);
con.Open();
object img = cmd.ExecuteScalar();
try
{
returnnew MemoryStream((byte[])img);
}
catch
{
returnnull;
}
finally
{
con.Close();
}
}
publicbool IsReusable {
get {
returnfalse;
}
}
}
C#
using System.Data;
using System.Data.SqlClient;
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;
publicpartialclassright7image : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["transfer"].ConnectionString);
string branchid = "";
protectedvoidPage_Load(object sender, EventArgs e)
{
branchid = Session["UserName"].ToString();
if (IsPostBack == false)
{
Image1.ImageUrl = "right7.ashx?BranchId=" + branchid;
Image2.ImageUrl = "right7old.ashx?BranchId=" + branchid;
}
}
protectedvoidLinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Images.aspx");
}
protectedvoidButton1_Click(object sender, EventArgs e)
{
//update//1st copy using ptr
SqlCommand cmdptr = new SqlCommand("copyprevimgr7", con);
cmdptr.CommandType = CommandType.StoredProcedure;
con.Open();
cmdptr.Parameters.AddWithValue("@BranchId", branchid);
cmdptr.ExecuteNonQuery();
con.Close();
//2nd newlybrowse once updateleft1image
SqlCommand cmdupdate = new SqlCommand("updateright7", con);
cmdupdate.CommandType = CommandType.StoredProcedure;
con.Open();
cmdupdate.Parameters.AddWithValue("@BranchId", branchid);
if (FileUpload1.HasFile)
{
FileInfo left1info = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] left1content = newbyte[left1info.Length];
FileStream left1stream = left1info.OpenRead();
left1stream.Read(left1content, 0, left1content.Length);
left1stream.Close();
cmdupdate.Parameters.AddWithValue("@imgright7", left1content);
}
cmdupdate.Parameters.AddWithValue("@noter7", TextBox1.Text);
if (cmdupdate.ExecuteNonQuery() != 0)
{
con.Close();
clsdatasettransfer.ShowAlertMessage("Updated.....");
TextBox1.Text = "";
System.Threading.Thread.Sleep(2000);
Image1.ImageUrl = "right7.ashx?BranchId=" + Session["UserName"].ToString();
Image2.ImageUrl = "right7old.ashx?BranchId=" + Session["UserName"].ToString();
}
else
{
clsdatasettransfer.ShowAlertMessage("Updatefailed");
}
}
}
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
PJ MartinsRank #2,548 · 548 reputationPosted Jun 22, 2010, 1:18 PM EDT
FileInfo left1info = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] left1content = new byte[left1info.Length];
FileStream left1stream = left1info.OpenRead();
left1stream.Read(left1content, 0, left1content.Length);
left1stream.Close();
cmdupdate.Parameters.AddWithValue("@imgright7", left1content);
to
cmdupdate.Parameters.AddWithValue("@imgright7", FileUpload1.FileBytes);