Hi nabilabolo,
Refer below sample.
HTML
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button Text="Submit" OnClick="OnSubmit" runat="server" />
<hr />
<asp:Literal ID="ltEmbed" runat="server" />
Code
C#
protected void OnSubmit(object sender, EventArgs e)
{
ltEmbed.Visible = true;
if (!System.IO.Directory.Exists(Server.MapPath("~/Files")))
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/Files"));
}
fuUpload.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Files"), System.IO.Path.GetFileName(fuUpload.PostedFile.FileName)));
string file = "~/Files/" + System.IO.Path.GetFileName(fuUpload.PostedFile.FileName);
string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"500px\" height=\"300px\">";
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(file));
}
VB.Net
Protected Sub OnSubmit(ByVal sender As Object, ByVal e As EventArgs)
ltEmbed.Visible = True
If Not IO.Directory.Exists(Server.MapPath("~/Files")) Then
IO.Directory.CreateDirectory(Server.MapPath("~/Files"))
End If
fuUpload.SaveAs(IO.Path.Combine(Server.MapPath("~/Files"), IO.Path.GetFileName(fuUpload.PostedFile.FileName)))
Dim file As String = "~/Files/" & IO.Path.GetFileName(fuUpload.PostedFile.FileName)
Dim embed As String = "<object data=""{0}"" type=""application/pdf"" width=""500px"" height=""300px"">"
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(file))
End Sub