make a table theres 2 tables theres a database table theres a table on menu options
which table ? and that is never going to string together ("~/files/,,,name file...")
i did ask for tuturial as i have never done that ,ok i know you might be thinking its no hard but ignatandrei when you first started you must of surely asked for help at beginning thats all i ask for to get it to work , so a tuturial would be good thanks
ramiramilu i liked that tuturial see in the .cs part i see lot off red underlines
can you tell me if this is correct on how ive done that
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
private void StartUpLoad()
{
//get the file name of the posted image
string imgName = FileUpload1.FileName.ToString();
//sets the image path
string imgPath = "ImageStorage/" + imgName;
//then save it to the Folder
FileUpload1.SaveAs(Server.MapPath(imgPath));
//get the size in bytes that
int imgSize = FileUpload1.PostedFile.ContentLength;
//validates the posted file before saving
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
if (FileUpload1.PostedFile.ContentLength > 5120) // 5120 KB means 5MB
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big')", true);
}
else
{
//save the file
//Call the method to execute Insertion of data to the Database
ExecuteInsert(imgName, imgSize, imgPath);
Response.Write("Save Successfully!");
}
}
}
private string GetConnectionString()
{
//sets the connection string from your web config file. "DBConnection" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString;
}
private void ExecuteInsert(string name, int size, string path)
{
richkyrs
Member
436 Points
500 Posts
upload images
Apr 08, 2012 09:19 PM|LINK
is there any videos or tuturials of how my users can upload a image on to there profile
i see loads of videos vb, but webforms c# would be great help there
ignatandrei
All-Star
135073 Points
21662 Posts
Moderator
MVP
Re: upload images
Apr 08, 2012 11:10 PM|LINK
Make a table with id user and a FilePath string
Store the file unser Server.MApPath("~/files/,,,name file...")
Write into the table the info.
Retrieve when show the
of the user page.richkyrs
Member
436 Points
500 Posts
Re: upload images
Apr 09, 2012 12:22 AM|LINK
make a table theres 2 tables theres a database table theres a table on menu options
which table ? and that is never going to string together ("~/files/,,,name file...")
i did ask for tuturial as i have never done that ,ok i know you might be thinking its no hard but ignatandrei when you first started you must of surely asked for help at beginning thats all i ask for to get it to work , so a tuturial would be good thanks
ignatandrei
All-Star
135073 Points
21662 Posts
Moderator
MVP
Re: upload images
Apr 09, 2012 08:10 AM|LINK
Name the table that you want.
http://www.codeproject.com/Articles/21208/Store-or-Save-images-in-SQL-Server
However, it does not show how to retrieve the image in the "Profile" page - but in other page.
srinivaskotr...
Star
11228 Points
1792 Posts
Re: upload images
Apr 09, 2012 08:25 AM|LINK
hi
find this video
http://www.youtube.com/watch?v=yREOtC8w4xw (video)
http://stackoverflow.com/questions/1978717/how-to-upload-an-image-file-to-active-directory-user-profile-in-c (detail code)
Thanks,
Srinivas Kotra.
ramiramilu
All-Star
95493 Points
14106 Posts
Re: upload images
Apr 09, 2012 09:08 AM|LINK
http://geekswithblogs.net/dotNETvinz/archive/2009/08/02/uploading-and-storing-image-path-todatabase-and--image-to.aspx
Thanks,
JumpStart
richkyrs
Member
436 Points
500 Posts
Re: upload images
Apr 09, 2012 04:10 PM|LINK
ramiramilu i liked that tuturial see in the .cs part i see lot off red underlines
can you tell me if this is correct on how ive done that
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
private void StartUpLoad()
{
//get the file name of the posted image
string imgName = FileUpload1.FileName.ToString();
//sets the image path
string imgPath = "ImageStorage/" + imgName;
//then save it to the Folder
FileUpload1.SaveAs(Server.MapPath(imgPath));
//get the size in bytes that
int imgSize = FileUpload1.PostedFile.ContentLength;
//validates the posted file before saving
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
if (FileUpload1.PostedFile.ContentLength > 5120) // 5120 KB means 5MB
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big')", true);
}
else
{
//save the file
//Call the method to execute Insertion of data to the Database
ExecuteInsert(imgName, imgSize, imgPath);
Response.Write("Save Successfully!");
}
}
}
private string GetConnectionString()
{
//sets the connection string from your web config file. "DBConnection" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString;
}
private void ExecuteInsert(string name, int size, string path)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO ImageInfo (ImageName, ImageSize, ImagePath) VALUES "
+ " (@ImgName,@ImgSize,@ImgPath)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@ImgName", SqlDbType.NVarChar, 50);
param[1] = new SqlParameter("@ImgSize", SqlDbType.BigInt, 9999);
param[2] = new SqlParameter("@ImgPath", SqlDbType.VarChar, 50);
param[0].Value = name;
param[1].Value = size;
param[2].Value = path;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
StartUpLoad();
}
}
evello880
Member
226 Points
75 Posts
Re: upload images
Apr 09, 2012 06:15 PM|LINK
http://geekswithblogs.net/dotNETvinz/archive/2009/08/02/uploading-and-storing-image-path-todatabase-and-image-to-folder.aspx
http://forums.asp.net/p/1443621/3278234.aspx
richkyrs
Member
436 Points
500 Posts
Re: upload images
Apr 09, 2012 08:11 PM|LINK
is ok got that error fixed was imageSource folder thanks for your efforts guys