.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Problem in "Upload a picture into data base" because is in

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
Hi guys. I can upload a picture into database by this code correctly in a web page without "UpdatePanel": ******************************** SqlConnection connection = null; try { Byte[] imgByte = null; if (FileUpload.HasFile && FileUpload.PostedFile != null) { HttpPostedFile File = FileUpload.PostedFile; imgByte = new Byte[File.ContentLength]; File.InputStream.Read(imgByte, 0, File.ContentLength); } // Insert the employee name and image into db string conn = "Data Source=PC5;Initial Catalog=LaptopStore;Integrated Security=True"; connection = new SqlConnection(conn); connection.Open(); string sql = "INSERT INTO test(image) VALUES(@image) SELECT @@IDENTITY"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@image", imgByte); int id = Convert.ToInt32(cmd.ExecuteScalar()); lblResult.Text = String.Format("Employee ID is {0}", id); } catch { lblResult.Text = "There was an error"; } finally { connection.Close(); } ******************************************** But when I want to use this code in a

View Complete Post

More Related Resource Links

Problem with UpdatePanel postback

Hello,I have a Modal Popup window, inside an Update Panel object, that has the following layout:A Title areaA Content area with a tabstrip of 5 tabsA footer area with two buttons (Save and Cancel) and an UpdateProgressIn 3 of the five tabs I have:an UpdatePanel (UpdateMode=Conditional) that wrapsA collection of LinkButtons objectA gridviewAnother Panel object to be showed as a Nested Modal PopupNO update ProgressBoth the link collection and the gridview Select event will open the nested Modal window that contains a custom Usercontrol that is used to add new or edit object of the related gridview like in the code sample below//click handler of the LinkButton protected void btnNewPhone_Click(object sender, EventArgs e) { //Setup properties of the UserControl code omitted // ... //Show the nested Popup this.mpePopupPhone.Show(); } //handler for the gridview selectedIndex event protected void gvPhones_SelectedIndexChanged(object sender, EventArgs e) { //Setup properties of the UserControl code omitted // ... //Show the nested Popup this.mpePopupPhone.Show(); } Please note that: I am using the ModalPopupExtender show/hide behaviors using only server-side code. Also, the ModalPopupExtender objects for nested modal windows does not have the OkControlID & CancelControlID set. As the content of nested modal window is only a single user contro

UpdatePanel and FileUpload

Hi, i have wide customer table that i handle with a big DetailView nested inside an UpdatePanel for faster interaction. Works like a charm. Now they ask me to allow the user to upload a file, but when i add it in the detail view and i save data i get no file at all, as if putting it into an updatepanel do not allow him to send the file any more. Is there some setting i have to put so to make it work ? thanks in advance, Fabrizio

Problem with Dynamic Controls inside an UpdatePanel

Hello Everybody ,I have this problem,if anyone could help me i'll be so gratefull. I had been created some dynamic radio buttons in a loop inside a dinamy table which is inside an UpdatePanel , but i can not handle the events my code is below:public void MetodoCreacion(){RadioButton RBtn = null;Table table = new Table();TableRow row = null;TableCell cell = null;for (int i = 0; i < 5; i++){row = new TableRow();cell = new TableCell();RBtn = new RadioButton();RBtn.ID = "RBGN_" + i.ToString();RBtn.GroupName = "RBGN1";RBtn.Text = "Opcion " + i.ToString();RBtn.CheckedChanged += new EventHandler(RBtn_CheckedChanged);RBtn.AutoPostBack = true;cell.Controls.Add(RBtn);row.Controls.Add(cell);table.Controls.Add(row);}UpdatePanel1_UpdatePanelAnimationExtender.Controls .Add(table);}public void RBtn_CheckedChanged (object sender, EventArgs e){Label1.Text = ((RadioButton)sender).ID;}and the controls doesent call the event ...thanks a lot

fileupload in UpdatePanel

Hi there, Can anybody tell me why this is working but not with UpdatePanel (commented lines here)?<body> <form id="form1" runat="server"> <div> <!--<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> --> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <!--<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate>--> <hr /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <asp:FileUpload ID="FileUpload1" runat="server" /><br /> <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> <hr /> <!--</ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel>--> <br /> <br /> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Labe

FileUpload and UpdatePanel: FileUpload.HasFile is always FALSE.

Hello. I'm developing an ASP.NET application with C# and Visual Studio 2008 SP1. I'm using WebForms. I have an ASPX page with two UpdatePanels, one on the left that holds a TreeView and other on the right where I load dynamically user controls. One user control, that I used on right panel, has a FileUpload control and a button to save that file on server. The ascx code to save control is:     <asp:UpdatePanel ID="UpdatePanelBotons" runat="server" RenderMode="Inline"      UpdateMode="Conditional">    <ContentTemplate>     <asp:Button ID="Save" runat="server" Text="Guardar"         onclick="Save_Click" CssClass="button" />     </ContentTemplate>     <Triggers>      <asp:PostBackTrigger ControlID="Save" />     </Triggers>    </asp:UpdatePanel> I make a full postback to upload the file to the server and save it to database. But I always getting False on FileUpload.HasFile. I problem is the right UpdatePanel. I need it to load dynamically the user controls. This panel has three UpdatePanels to load the three user controls that I

problem with datalist in updatepanel


Hi! i try to make a search part. there is a textbox which will be used for search context. also, i need to list category names. i don't use dropdownlist because its styles(for example border-style)doesn't change. So i tyr to do like this:i use a label and datalist. when clicking the label, datalist is showing. when i click the category name on datalist, it will be shown on label.(label is not in datalist.)my problem starts at that point. when i click category name on datalist , page is being postback. so i put datalist into updatepanel. but this time , i click category name on datlist,nothing occurs.(category name doesn't shown on label).my code is below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

FileUpload path problem


I have not been able to uplaod a file to my web page although the code I am using works if I copy it locally. Perhaps I am missing something in the path or I need to change some security setting on the web page?

   protected void btnUpload_Click(object sender, EventArgs e)
        SelectedFileName.InnerHtml = txtFileField.PostedFile.FileName;
        FileType.InnerHtml = txtFileField.PostedFile.ContentType;

        // convert bytes to Kbytes
        int size = txtFileField.PostedFile.ContentLength / 1024;
        FileSize.InnerHtml = (size.ToString() + " KB");
        uploadDetails.Visible = true;

        string strFileName = txtFileField.PostedFile.FileName;
        string c = Path.GetFileName(strFileName);

            // not sure if this path is correct. not working anyway
            txtFileField.PostedFile.SaveAs("~/" + c); 
            feedBack.InnerHtml = "File uploaded successfully.";
        catch (Exception exp)
            string message = "File did not upload, please try again";
            feedBack.InnerHtml = message + "\n" + exp.Message.ToString();
            uploadDetails.Visible= false;
Thanks for any help.

FileUpload.SaveAs Problem


I'm uploading multiple PDF files from a CD to a folder on a server locally on the server itself. My problem is that the filenames and the PDF files is being uploaded, but the content of those PDF files themselves are missing. Their size is 0KB. 

FileUpload1.SaveAs(("C:\Documents and Settings\ABC\ABCD\ABCDE\PDF\" & Path.GetFileName((files(intCount1).ToString))
Not sure what i'm doing wrong here. I've tried a lot of other ways and I either get the path isn't found or or access is denied.
Thanks in advance for any help you guys can provide.




Fileupload problem



Can anybody help me out to clear the error. I am struggling from past few hours, my problem is this:

    private string SavePostedFiles(DevExpress.Web.ASPxUploadControl.UploadedFile uploadedFile)
        string ret = "";
        string fup;
        if (uploadedFile.IsValid)

Problem with Editing image inside DetailsView inside UpdatePanel



I have a problem and I really hope you'll be able to help me.

I'm trying to add and edit an image which is located in a detailsview which is inside an UpdatePanel. After I read relevant topics in the forum I installed the Ajax Control Toolkit. Below is my source code. When I used it only for insert new image it worked great. The problem caused when I tried to implement it on the Edit mode, i.e. when I tried to edit the image and upload a different image.  Unfortunately it didn't work as I hoped. Nothing happend and the image hasn't been changed. I also tried to change the IDs (AsyncFileUpload ID) to be the same in both places but it didn't work either.

The source code:

<asp:DetailsView ID="dvMovie" runat="server" Height="50px" Width="695px"
                    AutoGenerateRows="False" DataSourceID="sdsMovieById"      
                     BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"

MVC Fileupload problem


hey guys I'm trying to write a simple file upload page using ASP MVC2.

I've read some blog post so I started like this

 foreach (string file in Request.Files)
                HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                if (hpf.ContentLength > 0)
                    string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads")

FileUpload Problem


Hi, I am having problems storing the path where an image is saved.

I will like to sotre the path: _images\DemoImg.jpg  and not C:\inetpub\wwwroot\sweb\_images\DemoImg.jpg

With path saved as C:\inetpub\wwwroot\sweb\_images\DemoImg.jpg I cant read the image unless I change the path in the database.

Any help or suggestions will be very appreciated.


FileUpload in DetailsView fails with UpdatePanel



I'm developing a project in ASP.NET C#, with SQL Server Express 2005, on Windows Vista.

I have a GridView, and a DetailsView on an aspx page.

The GridView displays all items in a database that has a certain ProductID (The items is Pictures)

The DetailsView displays the selected row of the GridView.

In the DetailsView I have 3 FileUpload controls, for 3 different size of images.

My update functionallity works just fine. I catch the OnUpdating event of it's ObjectDataSource, and uses FindControl to get each FileUpload Control, and executes the FileUpload.SaveAs() method if the user provided a new Image.

My problem occurs when I want to Insert a new image. No matter what - all my FileUpload's HasFile property is always false.

I was trying different things, and then I removed the UpdatePanel from the page. That solved my problem, but I really want to use the UpdatePanel. What I found really strange is, that the code very much identic to the code for inserting, works fine when I'm updating.

I use kind of the same idea as provided in this: http://www.asp.net/Learn/DataAccess/tutorial56cs.aspx?tabid=63 article. I just have an UpdatePanel arround both the GridView and DetailsView.

Any ideas on what might be wrong?

Serious problem on UpdatePanel and GridView (Input string was not in a correct format)


I have implemented a custom gridview paging method using the pagertemplate tag. The source code is the following:



<asp:UpdatePanel ID="UpdatePanel1" runat="server">
      		<fieldset class="ads">
			<br />            
            <asp:GridView ID="gvResults" runat="server" AutoGenerateColumns="False" DataKeyNames="CHId" CssClass="grid" GridLines="None" AllowPaging="true" AllowSorting="true&q

updatepanel problem for IE


hi i have update-panel which works fine in Google chrome, Mozilla, but not in IE(6,7 and 8). when i click refresh button postback is happening.

Any suggestions plz

Thank you


fileupload problem


below the codes works. it save files to database whenever user click on it.

but what i want is user uploaded a file to database, and when he uploads again, the uploaded file will replace the previous file leaving the database only have a single file all times. instead of keep on making a new row to store files.

help to correct my code...thanks all.....

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
        If FileExtensionIsApproved(fUpload.HasFile) Then
            Dim test = fUpload.PostedFile.FileName
            Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ToString)
            Dim da As New SqlDataAdapter("Select * From files", con)
            Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
            Dim ds As New DataSet()
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey
            Dim fs As New FileStream(test, FileMode.OpenOrCreate, FileAccess.Read)
            Dim MyData(fs.Length) As Byte
            fs.Read(MyData, 0, fs.Length)
            da.Fill(ds, "Mydata")
            Dim myRow As DataRow
            myRow = ds.Tables("Mydata").NewRow()

asp .net updatepanel problem......



i am using 2 ddl, 1 gridview & 3 update panels for each in my page.

now  i want update my gridview, when any ddl was changing.....

how to do this....



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend