Click here to Skip to main content
15,895,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
actually i am working with image slideshow the first images related to company are sliding but the next image related to sys date sliding but with blank ie overlapped image one image over another but saving into folder and in databse
so i am sending two pages code ie uploadsit.aspx.cs
and seperate.aspx.cs where that problem i cant guess any body helpme
uploadsite.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Data;
using System.Data.SqlClient;


public partial class upload_site : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
//string filename = FileUpload1.FileName;
//FileUpload1.PostedFile.SaveAs(Server.MapPath(@"~\Upload\" + filename.Trim()));


//string path = @"~\Upload\" + filename.Trim();

if (Add.Checked == true)
{
try
{
string CS = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand();
//string filename = FileUpload1.FileName;
string OldImagePath = FileUpload1.FileName;
//FileUpload1.PostedFile.SaveAs(Server.MapPath(@"~\Upload\"));
FileUpload1.PostedFile.SaveAs(Server.MapPath(@"~\Upload\" + OldImagePath.Trim()));
string path = @"~\Upload\" + OldImagePath.Trim();
//string path = @"~\Upload\";
cmd = new SqlCommand("insert into imagepath(ID,ImageName,CurrentDate,OldImagePath)values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + path + "')", con);
cmd.CommandType = CommandType.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lblStatus.Text = " Uploaded Successfully ";
ChangeBackground(OldImagePath, path);

}
}
catch
{
lblStatus.Text = "Please try again later!";
}


}
else if (Delete.Checked == true)
{
string CS = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";
SqlConnection con = new SqlConnection(CS);
SqlCommand cmd = new SqlCommand("delete from imagepath where ID='" + TextBox1.Text + "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lblStatus.Text = " deleted successfully ";


}


}
private void ChangeBackground(string OldImagePath, string path)
{
System.Drawing.Image imageBackground = System.Drawing.Image.FromFile(@"C:\temp\images.jpg");
System.Drawing.Image imageOverlay = System.Drawing.Image.FromFile(@"C:\Users\admin\Documents\Visual Studio 2012\WebSites\upload and announcement\Upload\" + OldImagePath.Trim() + "");

System.Drawing.Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
using (Graphics gr = Graphics.FromImage(img))
{
gr.DrawImage(imageBackground, new Point(0, 0));
gr.DrawImage(imageOverlay, new Point(0, 0));
}
// img.Save(@"~\Upload\output.png", ImageFormat.Png);
img.Save(@"C:\Users\admin\Documents\Visual Studio 2012\WebSites\uploadsite\Upload\" + TextBox2.Text + ".png", ImageFormat.Png);
img.Save(@"C:\temp\" + TextBox2.Text + ".jpeg", ImageFormat.Jpeg);
string impath = @"C:\Users\admin\Documents\Visual Studio 2012\WebSites\uploadsite\Upload\" + TextBox2.Text + ".png";
Label6.Text = "success";
}

protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("separate.aspx");
}
}

seperate.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;



public partial class separate : System.Web.UI.Page
{
static DataTable dt;
static int TotalRecords, CurrentRecord;
protected void Page_Load(object sender, EventArgs e)
{




//Repeater1.DataSource =GetEvents();
////Repeater1.DataBind();
if (!Page.IsPostBack)
{

string sqlconstr = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";
SqlConnection con = new SqlConnection(sqlconstr);
SqlDataAdapter sqlda = new SqlDataAdapter("select * from imagepath where CurrentDate is NULL union ALL select * from imagepath where convert(varchar(20), CurrentDate, 101) = convert(varchar(20), getdate(), 101)", con);
dt = new DataTable();
sqlda.Fill(dt);
TotalRecords = dt.Rows.Count;
Image1.ImageUrl = "~/Upload/" + dt.Rows[0]["ImageName"].ToString();

//Response.Redirect("uploadsite.aspx");
SqlDataAdapter da1 = new SqlDataAdapter("select ImageName from imagepath where convert(varchar(20), CurrentDate, 101) = convert(varchar(20), getdate(), 101)", sqlconstr);
DataSet ds1 = new DataSet();

da1.Fill(ds1, "imagepath");


string s1 = string.Empty;

if (ds1.Tables["imagepath"].Rows.Count > 0)
{

s1 += " HappyBirthday ";
s1 += ds1.Tables["imagepath"].Rows[0][0].ToString();
}
s1 += " ";
if (ds1.Tables["imagepath"].Rows.Count > 1)
{
s1 += " HappyBirthday ";
s1 += " ";


s1 += ds1.Tables["imagepath"].Rows[1][0].ToString();
}
s1 += " ";
if (ds1.Tables["imagepath"].Rows.Count > 2)
{
s1 += " HappyBirthday ";
s1 += " ";

s1 += ds1.Tables["imagepath"].Rows[2][0].ToString();
}
s1 += " ";
if (ds1.Tables["imagepath"].Rows.Count > 2)
{
s1 += " HappyBirthday ";
s1 += " ";

s1 += ds1.Tables["imagepath"].Rows[2][0].ToString();
}

lt1.Text = s1.ToString();


}

}
// string sqlconstr = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";


protected void Timer11_Tick(object sender, EventArgs e)
{
CurrentRecord++;
if (CurrentRecord == TotalRecords)
{
CurrentRecord = 0;

}
Image1.ImageUrl = "~/Upload/" + dt.Rows[CurrentRecord]["OldImagePath"].ToString();
//Image1.ImageUrl = @"C:\Users\admin\Documents\Visual Studio 2012\WebSites\uploadsite\Upload\";
}

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900