|
hi,
use the code below,
if (FileUpload1.HasFile)
{
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] branchcontent = new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent, 0, branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@BranchPicture", (branchcontent == null ? DBNull.Value : branchcontent));
}
Hope this will help
|
|
|
|
|
I have made some changes in the above reply
if (FileUpload1.HasFile)
{
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] branchcontent = new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent, 0, branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@BranchPicture", (branchcontent == null ? DBNull.Value : branchcontent));
}
else
{
cmdsave.Parameters.AddWithValue("@BranchPicture", DBNull.Value);
}
|
|
|
|
|
hi iam using asp.net with c#
i have written the code to save the image in database.the code works fine when i browse and upload the picture it will save in database , but some times i have no images so i dont want to upload images that time it is giving error , even though my data base field is allow null
error
System.ArgumentException: The path is not of a legal form.
the code is
===========
SqlCommand cmdsave = new SqlCommand("AddBranchProc11", con);
cmdsave.CommandType = CommandType.StoredProcedure;
con.Open();
cmdsave.Parameters.AddWithValue("@BranchId", txtbranchid.Text);
cmdsave.Parameters.AddWithValue("@BranchName", txtBranchname.Text);
cmdsave.Parameters.AddWithValue("@CompanyId", ddlcompanyid1.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@ContractNo", txtcontractno.Text);
cmdsave.Parameters.AddWithValue("@Region", ddlRegions.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@City", txtcity.Text);
cmdsave.Parameters.AddWithValue("@Area", txtarea.Text);
cmdsave.Parameters.AddWithValue("@Address", txtaddress.Text);
cmdsave.Parameters.AddWithValue("@StartDate", txtstartdate1.Text);
cmdsave.Parameters.AddWithValue("@EndDate", txtEnd.Text);
cmdsave.Parameters.AddWithValue("@ContractReminder", ddlcontractreminder.SelectedItem.Value); FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[]branchcontent=new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent,0,branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@ReminderType", ddlremindertype.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@BranchPicture",branchcontent);
if (cmdsave.ExecuteNonQuery()!= 0)
{
Functions.ShowAlertMessage("saved");
}
i want to save the information without image also , can you correct my code which helps me
|
|
|
|
|
hi,
Use this code below
cmdsave.Parameters.AddWithValue("@BranchPicture", (branchcontent == null ? DBNull.Value : branchcontent));
Hope this will help.
|
|
|
|
|
Why dont you check if file is chosen or not before you do extract file bytes.
There is a property called HasFile which determines if a file is selected.
byte[] branchcontent;
if (FileUpload1.HasFile)
{
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] branchcontent = new byte[branchinfo.Length];
using (FileStream branchstream = branchinfo.OpenRead())
{
branchstream.Read(branchcontent, 0, branchcontent.Length);
branchstream.Close();
}
}
cmdsave.Parameters.AddWithValue("@BranchPicture",branchcontent);
Do like this.
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
This might not be answer of your question but still I am suggesting because saving whole image in database is no-way a good practice. It will create huge overload on SQL for bringing and saving this much data rapidly.
Instead, you should save those images into one folder in your project and save its relative path like "../images/uploaded/something.jpeg" into varchar field in database. it will save mammoth time while executing.
And while displaying, just bring varchar filed path from database and assign into src field of img
|
|
|
|
|
You should probably check for FileUpload1.HasFile before you set the @ContractReminder param and do all that other stuff. Then do a simple if/then using HasFile and set the value of the param to DBNull.Value if there isn't a file.
|
|
|
|
|
Hi Every1,
I visited a site and found a search bar which is not moving when we scroll down or up the web page .http://www.plastemart.com/plasticnews.asp#[^].this is the link for that page and you can find a search bar on the right lower corner.Please help me to make one similar to that.I really want to know how can we do that in asp.net...
Thanks in advance
|
|
|
|
|
It's a div with top position absolute .
When you view the source code, check this line:
<div style="visibility: visible; position: absolute; left: 19px; top: 445px; vertical-align: top;" id="myChaser11">
All the controls are put inside the div tag and so they have an absolute position against the page. It will always remain 445px below the top of the page.
..Go Green..
|
|
|
|
|
Hi,
I've added some code to my RowDataBound event handler to allow the user to select a row in a GridView. Here's the code:
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.MyGridView, "Select$" + e.Row.RowIndex);
Nothing special there, it works fine
The trouble is, there's a CheckBox control, a templated one, and I need to set it "read-only" rather than disabled as I don't want it greyed out because it doesn't look great.
I know how to access a templated control and I know how to set a CheckBox control to read-only so I tried the following but it didn't work:
((CheckBox)e.Row.FindControl("MyCheckBox")).Attributes.Add("onclick", "return false;");
I think it's because I've already set the "onclick" attributes for the row but I don't know how to get the control attributes set as well as the row.
Any ideas?
|
|
|
|
|
hey guys i have a image control in my web form. i want to zoom that image when the user clicks the image.
The image is being retrieved from folder . there are two buttons(Next and Previous) to traverse the images and the information about the image name is retrieved from database.
When the first image loads the zooming works fine. but when i click on next or previous the jQuery for the particular images stops working .
According to what i think is the CssClass is being lost for image control. i have tried mentioning
image1.CssClass="magnify" in every function explicitly but does not work
|
|
|
|
|
Do not use URGENT, it is rude. We are here voluntarily to answer questions and what is urgent to you is not to anyone else.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
hi,
This is regarding textbox control, while seeing the page it is showing one value eg: 12/31/1969 but in the view source code of that page shows 12/58/2010.
How can it possible.
|
|
|
|
|
Well, are you looking at the same text control? Are there any other text controls in the page?
The data may be have manipulated by JavaScript code. Is there any JavaScript code that runs on page load?
|
|
|
|
|
Copy "12/31/1969" From your web page. Open the View Soruce, Search >"12/31/1969". Check the result.
|
|
|
|
|
maybe you are updating the value using a client side code (javascript).
Regards,
Jamil
|
|
|
|
|
Hi,
I try to manage the absence of students in the exams, try to insert the id of students absent for each matter,to facilitate that to the user i want insert id_student at once (not one after one by textbox simple)is ther any control or method to do that?
Thanks
|
|
|
|
|
Yes, you can take listbox which shows you student id and name (combination, however in background it will give you ids)
so you can select multiple items from listbox.
On each matter, there is two checkbox (absent and present)
so just select multiple student from listbox
and mark absent or present checkbox and insert it
into database.
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi!
I do not know if will be easy for the user ,because it is hundreds of students by by matter ,so i must show them all for and check those abcent.
Thanks .
|
|
|
|
|
Hi!
How we can paginate a listbox?
Thanks
|
|
|
|
|
You do not required to do pagination in listbox,
it will automatically shows you scroll bar...
The other best option it you do not want to use
listbox is create your custom control.
Because if you are using grid control then it will
not remember your selection when you select
options from multiple pages....
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Thanks Jinal Desai - LIVE,
creating user control seems complicated,I think using multiline textbox:
the user will simply enter ID of abcent students line and in the end I enter that id in the database by a clic buton ,Waht do you Think?
Thank you.
|
|
|
|
|
ya that will be also nice idea.
If you want to just take IDs then it is fine...
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi,
That's what I wanted ,it easier for the user but I did not know if there multiline textbox.
I do not know how to check if those id are correct,to prevent the user from making mistakes and insert an id which does not exist in the table student.
Thanks
|
|
|
|