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 LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 12:36 AM EDT
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));
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 12:37 AM EDT
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
aditya immadi186 reputationPosted Jul 30, 2013, 12:55 AM EDT
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 HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:00 AM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 1:03 AM EDT
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
}
aditya immadi186 reputationPosted Jul 30, 2013, 1:04 AM EDT
'">
'">
'">
'">
'">
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();
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:11 AM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 1:13 AM EDT
i modified your datalist just check it
'">
'">
'">
'">
'">
aditya immadi186 reputationPosted Jul 30, 2013, 1:19 AM EDT
scenario is one images under those image we have thier link images ..
Thanks and Regards
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:22 AM EDT
Regards,
Iftikar
aditya immadi186 reputationPosted Jul 30, 2013, 1:24 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:26 AM EDT
Font-Size="10pt" ForeColor="#336699" Width="100%" />
ImageUrl='<%# Bind("image", "~/Images-candidates/{0}")%>' />
'">
'">
'">
'">
'">
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 1:26 AM EDT
can you provide a screenshot how you want to show the image.
aditya immadi186 reputationPosted Jul 30, 2013, 1:31 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:35 AM EDT
Regards,
Iftikar
aditya immadi186 reputationPosted Jul 30, 2013, 1:39 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 1:40 AM EDT
ii modified your datalist design just.check that
'">
'">
'">
'">
'">
Are you able to get the image by using above code.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:41 AM EDT
ImageUrl='<%# Bind("image", "~/Images-candidates/{0}")%>' />
can you right click on image (userImage) from application and share the path
Regards,
Iftikar
aditya immadi186 reputationPosted Jul 30, 2013, 1:42 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:45 AM EDT
Regards,
Iftikar
aditya immadi186 reputationPosted Jul 30, 2013, 1:46 AM EDT
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
aditya immadi186 reputationPosted Jul 30, 2013, 1:48 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 1:50 AM EDT
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
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 1:50 AM EDT
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
aditya immadi186 reputationPosted Jul 30, 2013, 2:00 AM EDT
Thaks and Regards
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 2:03 AM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 2:13 AM EDT
i checked your code it uploading image to folder i just create a sample using your code just check the attached code.
aditya immadi186 reputationPosted Jul 30, 2013, 2:24 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 30, 2013, 2:31 AM EDT
Regards,
Iftikar
aditya immadi186 reputationPosted Jul 30, 2013, 4:03 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 4:16 AM EDT
your problem solved or not.
aditya immadi186 reputationPosted Jul 30, 2013, 6:38 AM EDT
'">
'">
'">
'">
'">
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 6:47 AM EDT
try this one
'<%# Eval("blog") %>'>
'<%# Eval("fblink") %>'>
'<%# Eval("twitter") %>'>
'<%# Eval("website") %>'>
'<%# Eval("wiki") %>'>
aditya immadi186 reputationPosted Jul 30, 2013, 6:50 AM EDT
aditya immadi186 reputationPosted Jul 30, 2013, 6:57 AM EDT
when usig this code,when i click on the fb or blog link page moves to top....and nothig happens...
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 6:58 AM EDT
Sometime it happens. Everyday in our life we learn. Keep coding.
Mark it as answered if it helps you
aditya immadi186 reputationPosted Jul 30, 2013, 7:05 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 30, 2013, 7:06 AM EDT