hi every body
i have a register web form where there are many textboxes and upload a photo for user it works fine when i upload photo but when i save without upload photo it gets me error how can i save data with or without upload photo ??
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Iftikar HussainPosted Jul 28, 2013, 11:46 PM
Regards,
Iftikar
alaaPosted Jul 28, 2013, 9:29 AM
and so how can i put soulation in code for this error using alret message or any suitable soulation
Iftikar HussainPosted Jul 28, 2013, 7:21 AM
Regards,
Iftikar
alaaPosted Jul 28, 2013, 6:57 AM
but some imges gets me error
Attempted to divide by zero.
Line 96: int sngRatio = origWidth / origHeight;
Line 97: int newWidth = 160;
Line 98: int newHeight = newWidth / sngRatio;
whats the soulation for this error
be sure that before i post any thing i try more and raed about it to find answer ny self
Iftikar HussainPosted Jul 28, 2013, 6:30 AM
";
";
Regards,
Iftikar
alaaPosted Jul 28, 2013, 6:27 AM
Iftikar HussainPosted Jul 28, 2013, 6:16 AM
I believe, here user is the user id and user will always upload .jpg file.
therefor it is not required to save any details related to photo to database.
Regards,
Iftikar
alaaPosted Jul 28, 2013, 5:56 AM
{
string user = utility.ReadFromCookie("login", "U", Request);
UsersInfo reg = new UsersInfo();
// First we check to see if the user has selected a file
// if (FUpload.HasFile)
if(FUpload.PostedFile.ContentLength >= 0)
{
// Find the fileUpload control
string filename = FUpload.FileName;
// Check if the directory we want the image uploaded to actually exists or not
if (!Directory.Exists(MapPath(@"../Users/UsersImg/")))
{
// If it doesn't then we just create it before going any further
Directory.CreateDirectory(MapPath(@"Uploaded-Files"));
}
// Specify the upload directory
string directory = Server.MapPath(@"../Users/UsersImg/");
// Create a bitmap of the content of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(FUpload.FileContent);
// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth / origHeight;
int newWidth = 160;
int newHeight = newWidth / sngRatio;
// Create a new bitmap which will hold the previous resized bitmap
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
// Create a graphic based on the new bitmap
Graphics oGraphics = Graphics.FromImage(newBMP);
// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
// Save the new graphic file to the server
newBMP.Save(directory +user+".jpg");
// Once finished with the bitmap objects, we deallocate them.
originalBMP.Dispose();
newBMP.Dispose();
oGraphics.Dispose();
// Write a message to inform the user all is OK
string savepath = (@"../Users/UsersImg/" + user + ".jpg").ToString();
Label1.Text = "File Name: " + filename + "
";
Label1.Text += "Content Type: " + FUpload.PostedFile.ContentType + "
";
Label1.Text += "File Size: " + FUpload.PostedFile.ContentLength.ToString() + "";
// Display the image to the user
imgUser.Visible = true;
imgUser.ImageUrl = @"../Users/UsersImg/" + user +".jpg";
if (Session["addinfoarray"] != null)
{
ArrayList al2 = (ArrayList)Session["addinfoarray"];
if (reg.Register(CryptoUtil.DecryptTripleDES(user),(string)al2[0],(string)al2[1],(string)al2[2],(string)al2[3],(string)al2[4],(string)al2[5],(string)al2[6],(string)al2[7],(string)al2[8],(string)al2[9],(string)al2[10],(string)al2[11],(string)al2[12],savepath) == true)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('your data is saved')", true);
Response.Redirect("Profile.aspx?=n"+user);
}
}
} //end if 1
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('your profile isnt complete')", true);
Response.Redirect("Profile.aspx");
// Page.ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('No file uploaded!')", true);
}
}
Iftikar HussainPosted Jul 28, 2013, 5:45 AM
Regards,
Iftikar
Iftikar HussainPosted Jul 28, 2013, 4:59 AM
and share me your database design for the table where you are storing photo
Regards,
Iftikar
alaaPosted Jul 28, 2013, 4:53 AM
if (FUpload.HasFile)
{
// do something
}
else
{
// do something
}
i ask if i can do something like this
if (FUpload.HasFile=true || FUpload.HasFile=false )
{
// my code to save data with or without photo path will run here
}
Iftikar HussainPosted Jul 28, 2013, 2:00 AM
If your upload photo is not mandatory while registering the User details, then while saving the data just check like this
Note: I believe UploadPhoto filed in database is nullable
Regards,
Iftikar