Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have an issue to upload images with file extension .jpeg / .png / .bmp from database

User upload multiple type of images/document/pdf/jpeg etc.

Currently only pdf format can only display in page. and working fine

I am storing path of images/doc/pdf in data table

How can retrieve/display images/document/pdf/jpeg etc. into asp.net page


Pls advice me

Maideen

What I have tried:

<pre>        Dim embed As String = "<object data=""{0}"" type=""application/pdf"" width=""100%"" height=""500px"">"
        embed += "If you are unable to view file, you can download from <a href = ""{0}"">here</a>"
        embed += " or download <a target = ""_blank"" href = ""http://get.adobe.com/reader/"">Adobe PDF Reader</a> to view the file."
        embed += "</object>"
        ltEmbed.Text = String.Format(embed, ResolveUrl(Me.txtFilePath.Text))




Mssql Database table
CREATE TABLE [dbo].[CL_UPLoad_Document](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[DocNo] [varchar](20) NULL,
	[StaffCode] [varchar](20) NULL,
	[imgName] [varchar](100) NULL,
	[Path] [nvarchar](300) NULL,
 CONSTRAINT [PK_US_UPLoad_Docment] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Posted
Updated 1-Feb-19 8:45am

1 solution

Hi there,

I use two objects in my page, one for images and another one for PDFs, which I hide or show as needed.
<asp:Image ID="imgRespaldo" runat="server" CssClass="img-fluid" style="display:none" />

<div id="PDFObj" runat="server" class="col-12" style="display:none;" >
    <asp:Literal ID="ltObjPDF" runat="server"/>
</div>
Said objects reside inside an updatepanel.

Here's a code example:
private void DisplayImage(GridViewRow Row)
{

    StringBuilder embedPDFObj;

    //I Get my file name and path from a grid, and build the URL as needed.
    string fileName = Row.Cells[2].Text;
    string respaldoURL = "~/Respaldos/" +  Row.Cells[1].Text + "/" + fileName;

    if (fileName.EndsWith(".pdf"))
    {
        embedPDFObj = new StringBuilder("<object data=\"{0}\" type=\"application/pdf\" width=\"100%\" >");
        embedPDFObj.Append("<embed src=\"{0}\" type=\"application/pdf\"></embed>");
        embedPDFObj.Append("</object>");

        ltObjPDF.Text = string.Format(embedPDFObj.ToString(), ResolveUrl(respaldoURL));
        RootCore.SetDisplayStyle(PDFObj, true, UpdPanelImg);
    }
    else // Images
    {
        imgRespaldo.AlternateText = fileName;
        imgRespaldo.ImageUrl = respaldoURL;
        RootCore.SetDisplayStyle(imgRespaldo, true, UpdPanelImg);
    }
}
My "SetDisplayStyle" method is in charge of modifying the given control style's display setting.

Hope this helps, cheers!
 
Share this answer
 
Comments
Maideen Abdul Kader 1-Feb-19 19:28pm    
hiThank you for prompt reply.
I dont understand what is rootcore?
Pls advice me

thank you
alexvw 5-Feb-19 11:35am    
Hi there,

RootCore is a helper class I add to my projects, where I write methods that are of general interest/accessibility throughout the code.

The SetDisplayStyle method you can see, in the code example I sent you, is in charge of setting the display attribute of the style property of the signaled control. e.g. { style="display:none;" }

Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900