Click here to Skip to main content
15,887,746 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: TextArea value in C# Pin
Ali Al Omairi(Abu AlHassan)27-Feb-13 22:03
professionalAli Al Omairi(Abu AlHassan)27-Feb-13 22:03 
GeneralRe: TextArea value in C# Pin
Sandeep Mewara27-Feb-13 23:16
mveSandeep Mewara27-Feb-13 23:16 
AnswerRe: TextArea value in C# Pin
Ali Al Omairi(Abu AlHassan)27-Feb-13 20:06
professionalAli Al Omairi(Abu AlHassan)27-Feb-13 20:06 
GeneralRe: TextArea value in C# Pin
vanikanc28-Feb-13 2:38
vanikanc28-Feb-13 2:38 
GeneralRe: TextArea value in C# Pin
Ali Al Omairi(Abu AlHassan)4-Mar-13 4:13
professionalAli Al Omairi(Abu AlHassan)4-Mar-13 4:13 
QuestionDataset Issue Pin
Abhismart5527-Feb-13 3:18
Abhismart5527-Feb-13 3:18 
AnswerRe: Dataset Issue Pin
Abhismart5527-Feb-13 7:15
Abhismart5527-Feb-13 7:15 
QuestionProblems with display image byte() on image tag Pin
keidash27-Feb-13 0:36
keidash27-Feb-13 0:36 
Hello All,

I'm try to show images from database in a client side, but, I have been using many kinds of examples that I found and none work, none of the images shown. The last example I saw it's this:
Auto-bind byte[] to asp:Image[^]

I understand perfectly the example, but the images are still not displayed.

Someone help me a bit with this issue?

In summary, I'm use a HTML5 drag & drop files. Send the files via XMLHttpRequest in a FormData object. One handler take this files in byte() and store in SQL DataBase.

Client code:
JavaScript
$("#btnUploadFile").click(function () {
	    if (files.length <= 0) {
	        alert("Debe seleccionar algún fichero para subirlo.");
	    } else {
	        var expID = $("#ContentPlaceHolder1_hfExpId").val();
	        var formData = new FormData();
	        for (var i = 0; i < files.length; i++) {
	            alert(files[i].name);
	            formData.append('file', files[i]);
	        }
	        var xhr = new XMLHttpRequest();
	        xhr.open('POST', "FileHandler.ashx", true);
	        xhr.overrideMimeType('text/plain; charset=x-user-defined-binary');
	        xhr.setRequestHeader("ExpedienteID", expID);
	        xhr.onload = function () {
	            if (xhr.status === 200) {
	                RefreshFilePanel();
	            } else {
	                console.log('Something went terribly wrong...');
	            }
	        };
	        xhr.send(formData);
	    };


Handle code:
VB
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim documentBytes As Byte()
        Dim lExpId As String = context.Request.Headers("ExpedienteID")
        Dim fLenght As Integer
        
        If (context.Request.Files.Count > 0) Then
            Dim files As HttpFileCollection = context.Request.Files

            For i = 0 To files.Count - 1
                fLenght = files(i).ContentLength
                documentBytes = New Byte(fLenght - 1) {}
                context.Request.InputStream.Read(documentBytes, 0, fLenght)
'This save byte() image on SQL Database:
                UploadDocumentBy_ExpID(documentBytes, files(i).FileName, "Description" & lExpId.ToString, lExpId)
            Next
        End If
    End Sub



More late, I try to put this byte() in a image tag on grid.

aspx code:
XML
<asp:GridView ID="grdDocumentoByExp" runat="server" AutoGenerateColumns="false" Width="250px"
 DataSourceID="dtsDocumentByExpId">
 <Columns>
  <asp:BoundField DataField="Archivo" HeaderText="Archivo" />
  <asp:BoundField DataField="docId" HeaderText="docId" />
  <asp:BoundField DataField="Documento" HeaderText="Documento" Visible="false" />
    <asp:TemplateField HeaderText="Preview">
       <ItemTemplate>
         <asp:Image 
         ID="imgThumb" 
         runat="server"
         ImageUrl='<%# GetImage(Eval("Documento")) %>'
        />
       </ItemTemplate>
    </asp:TemplateField>                                                                
 </Columns>
</asp:GridView>


And the function GetImage in codebehind:
VB
Public Function GetImage(image As Object) As String
    Return "data:image/gif;base64," & Convert.ToBase64String(DirectCast(image, [Byte]()))
End Function


In all steps, there is no error, but I think that the error is posible located in the byte() file format..but i'm not sure.

Someone help me?

Sorry for my inglish and Thanks.
AnswerRe: Problems with display image byte() on image tag Pin
Ali Al Omairi(Abu AlHassan)4-Mar-13 3:26
professionalAli Al Omairi(Abu AlHassan)4-Mar-13 3:26 
Questionwhy team is not replyin gmy question Pin
prince_rumeel26-Feb-13 23:13
prince_rumeel26-Feb-13 23:13 
AnswerRe: why team is not replyin gmy question Pin
Richard MacCutchan27-Feb-13 1:09
mveRichard MacCutchan27-Feb-13 1:09 
GeneralRe: why team is not replyin gmy question Pin
prince_rumeel27-Feb-13 20:07
prince_rumeel27-Feb-13 20:07 
QuestionSign in with ASP.NET Pin
User 871522226-Feb-13 0:45
professionalUser 871522226-Feb-13 0:45 
AnswerRe: Sign in with ASP.NET Pin
Sandeep Mewara26-Feb-13 2:16
mveSandeep Mewara26-Feb-13 2:16 
AnswerRe: Sign in with ASP.NET Pin
ZurdoDev26-Feb-13 10:34
professionalZurdoDev26-Feb-13 10:34 
AnswerRe: Sign in with ASP.NET Pin
jain jinesh26-Feb-13 19:12
jain jinesh26-Feb-13 19:12 
GeneralRe: Sign in with ASP.NET Pin
User 871522226-Feb-13 20:47
professionalUser 871522226-Feb-13 20:47 
Questionunable to change Web.SiteMap Pin
jojoba201125-Feb-13 23:58
jojoba201125-Feb-13 23:58 
AnswerRe: unable to change Web.SiteMap Pin
Sandeep Mewara26-Feb-13 2:24
mveSandeep Mewara26-Feb-13 2:24 
GeneralRe: unable to change Web.SiteMap Pin
jojoba201126-Feb-13 4:12
jojoba201126-Feb-13 4:12 
QuestionBinding gridview from two tables Pin
demoninside925-Feb-13 22:45
demoninside925-Feb-13 22:45 
AnswerRe: Binding gridview from two tables Pin
David Mujica26-Feb-13 5:09
David Mujica26-Feb-13 5:09 
Questioncustom MVC authorization and Authorize Pin
Super Lloyd25-Feb-13 20:07
Super Lloyd25-Feb-13 20:07 
QuestionMVC Model + Entity Design Guidance Needed. Pin
nlarson1125-Feb-13 11:51
nlarson1125-Feb-13 11:51 
QuestionDevelop a Custom Login page Pin
Meherab Bhamgara25-Feb-13 3:24
Meherab Bhamgara25-Feb-13 3:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.