in aspx page
<%@ Page Title="newusercreation" Language="C#" MasterPageFile="~/master.Master" AutoEventWireup="true" CodeBehind="admim-newuser.aspx.cs" Inherits="ApComapaign.admim_newuser" %>
name | |
image | |
role | |
party | |
area | |
district | |
fblink | |
blog | |
wiki | |
website | |
my .CS code is
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;
using System.IO;
namespace ApComapaign
{
public partial class admim_newuser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btninsert_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUploadC.PostedFile.FileName);
FileUploadC.SaveAs(Server.MapPath("Images-candidates/" + filename));
string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(constring);
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "SP_detailsmain";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("name",txtnameC.Text);
cmd.Parameters.AddWithValue("image", FileUploadC.FileName);
cmd.Parameters.AddWithValue("role",ddlCRole.Text);
cmd.Parameters.AddWithValue("party",ddlCparty.Text);
cmd.Parameters.AddWithValue("area",txtarea.Text);
cmd.Parameters.AddWithValue("district",txtdis.Text);
cmd.Parameters.AddWithValue("fblink",txtfb.Text);
cmd.Parameters.AddWithValue("blog",txtblog.Text);
cmd.Parameters.AddWithValue("twitter",txttwitt.Text);
cmd.Parameters.AddWithValue("wiki",txtwiki.Text);
cmd.Parameters.AddWithValue("website",txtweb.Text);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
can any one tell me where is the bug is
Thanks and Regards
Sanjeeb LenkaPosted Jul 30, 2013, 11:06 AM
aditya immadiPosted Jul 30, 2013, 11:05 AM
Sanjeeb LenkaPosted Jul 30, 2013, 10:58 AM
Sometime it happens. Everyday in our life we learn. Keep coding.
Mark it as answered if it helps you
aditya immadiPosted Jul 30, 2013, 10:57 AM
when usig this code,when i click on the fb or blog link page moves to top....and nothig happens...
aditya immadiPosted Jul 30, 2013, 10:50 AM
Sanjeeb LenkaPosted Jul 30, 2013, 10:47 AM
try this one
'<%# Eval("blog") %>'>
'<%# Eval("fblink") %>'>
'<%# Eval("twitter") %>'>
'<%# Eval("website") %>'>
'<%# Eval("wiki") %>'>
aditya immadiPosted Jul 30, 2013, 10:38 AM
'">
'">
'">
'">
'">
Sanjeeb LenkaPosted Jul 30, 2013, 8:16 AM
your problem solved or not.
aditya immadiPosted Jul 30, 2013, 8:03 AM
Iftikar HussainPosted Jul 30, 2013, 6:31 AM
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 6:24 AM
Sanjeeb LenkaPosted Jul 30, 2013, 6:13 AM
i checked your code it uploading image to folder i just create a sample using your code just check the attached code.
Iftikar HussainPosted Jul 30, 2013, 6:03 AM
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 6:00 AM
Thaks and Regards
Iftikar HussainPosted Jul 30, 2013, 5:50 AM
protected void btninsert_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUploadC.PostedFile.FileName);
string userImagePath = Server.MapPath("/Images-candidates/");
FileUploadC.SaveAs(userImagePath + filename);
}
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 30, 2013, 5:50 AM
try this to save image:
FileUploadC.SaveAs(Server.MapPath("~/Images-candidates/" + filename));
if it not work plz provide your solution explorer screenshot . where actually the image folder
aditya immadiPosted Jul 30, 2013, 5:48 AM
aditya immadiPosted Jul 30, 2013, 5:46 AM
but my problem isthe folder"Images-candidates" didnot contain single image an till now i inserted 10 records from front end. but those are in database.but the folder remains empty
Thanks Regards
Iftikar HussainPosted Jul 30, 2013, 5:45 AM
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 5:42 AM
Iftikar HussainPosted Jul 30, 2013, 5:41 AM
ImageUrl='<%# Bind("image", "~/Images-candidates/{0}")%>' />
can you right click on image (userImage) from application and share the path
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 30, 2013, 5:40 AM
ii modified your datalist design just.check that
'">
'">
'">
'">
'">
Are you able to get the image by using above code.
aditya immadiPosted Jul 30, 2013, 5:39 AM
Iftikar HussainPosted Jul 30, 2013, 5:35 AM
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 5:31 AM
Sanjeeb LenkaPosted Jul 30, 2013, 5:26 AM
can you provide a screenshot how you want to show the image.
Iftikar HussainPosted Jul 30, 2013, 5:26 AM
Font-Size="10pt" ForeColor="#336699" Width="100%" />
ImageUrl='<%# Bind("image", "~/Images-candidates/{0}")%>' />
'">
'">
'">
'">
'">
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 5:24 AM
Iftikar HussainPosted Jul 30, 2013, 5:22 AM
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 5:19 AM
scenario is one images under those image we have thier link images ..
Thanks and Regards
Sanjeeb LenkaPosted Jul 30, 2013, 5:13 AM
i modified your datalist just check it
'">
'">
'">
'">
'">
Iftikar HussainPosted Jul 30, 2013, 5:11 AM
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 5:04 AM
'">
'">
'">
'">
'">
and my .CS is
if (!Page.IsPostBack)
{
string constrin = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
string query = "SELECT * FROM detailsmain";
SqlDataAdapter da = new SqlDataAdapter(query, constrin);
DataTable table = new DataTable();
da.Fill(table);
DataList1.DataSource = table;
DataList1.DataBind();
Sanjeeb LenkaPosted Jul 30, 2013, 5:03 AM
if (File.Exists(Server.MapPath("~/Images-candidates//" + filename))
{
lblMsg.Text = "This file is already added";
lblMsg.ForeColor = System.Drawing.Color.Red;
}
else
{
insert to database and save it to project
}
Iftikar HussainPosted Jul 30, 2013, 5:00 AM
Regards,
Iftikar
aditya immadiPosted Jul 30, 2013, 4:55 AM
and i have small dought...y my records are inserted 2 tymes if der is any master page error or something
and wen i write a code like this for binding images using datalist and it shows only name of the image instead of image
my aspxpage is
'">
'">
'">
'">
'">
and mmy .Cs file is
if (!Page.IsPostBack)
{
string constrin = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
string query = "SELECT * FROM detailsmain";
SqlDataAdapter da = new SqlDataAdapter(query, constrin);
DataTable table = new DataTable();
da.Fill(table);
DataList1.DataSource = table;
DataList1.DataBind();
Thanks and Regards
Iftikar HussainPosted Jul 30, 2013, 4:37 AM
You need save image with unique name in your database. Try like this
protected void btninsert_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUploadC.PostedFile.FileName);
filename =txtnameC.Text+"_"+filename;
FileUploadC.SaveAs(Server.MapPath("Images-candidates/" + filename));
string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(constring);
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "SP_detailsmain";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("name",txtnameC.Text);
cmd.Parameters.AddWithValue("image", filename );
cmd.Parameters.AddWithValue("role",ddlCRole.Text);
cmd.Parameters.AddWithValue("party",ddlCparty.Text);
cmd.Parameters.AddWithValue("area",txtarea.Text);
cmd.Parameters.AddWithValue("district",txtdis.Text);
cmd.Parameters.AddWithValue("fblink",txtfb.Text);
cmd.Parameters.AddWithValue("blog",txtblog.Text);
cmd.Parameters.AddWithValue("twitter",txttwitt.Text);
cmd.Parameters.AddWithValue("wiki",txtwiki.Text);
cmd.Parameters.AddWithValue("website",txtweb.Text);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
cmd.ExecuteNonQuery();
conn.Close();
}
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 30, 2013, 4:36 AM
write click on that image folder in the solution explorer and press Refresh in the menu.
you will able to see the image uploaded to that folder.
if same problem
change this line code and check
FileUploadC.SaveAs(Server.MapPath("~/Images-candidates/" + filename));