asp.net - uploaded file content preview -


In my asp.net web application, I want a third party file content preview tool, using that tool I uploaded Files (jpg or tiff or xls or pdf or text or document)

  protected void btn_upload_Click (object sender, EventArgs e) {try {if (flup_upload.HasFile) {_fname = flup_upload .FileName. ("", "") To change; String ext = path. Gate Extension (_fname) .lover (); If (ext == ".jpg" || ext == ".jpeg" || ext == ".bmp") {------} and if (ext == ".xls" || ext = = ".xlsx") {-----} else if (ext == ".pdf") {-----} else if (ext == ".tif" || ext == ".tiff" ) {---} else if (ext == ".txt") {----} else if (ext == ".docx" || ext == ".doc") {-----} I.e. upload a file (like jpg / tiff / xls / pdf / txt / doc) after capture (exception pre) {}}   

I want to show the file data in a preview Are there.

After

You can use the AJAX Control Lotty File Uploader to do this;

  & lt; Td> & Lt; Asp: label runat = "server" id = "myThrobber" style = "display: none: color: black;" & Gt; Loading .... & Lt; / Asp: label & gt; & Lt; Br / & gt; & Lt; Ajax: AsyncFileUpload id = "FileUploadGaurdianPic" runat = "server" ThrobberID = "MyTrobe" maximalofffile = "1" OnClientUploadComplete = "uploads full" onloadedcomplete = "file uploadloadpierge_uploaded complete" style = "margin-left: 0 pixels" /> & Lt; ASP: Image Runat = "Server" ID = "Image Gordan Tump" /> / Td> // temp image to show   

We have the OnUploadedComplete event, which is the function name of the javascript file. Apart from the Uploaded_Complete event for dealing with server side;

Note that I'm just getting the route here; Session ["GuardianPic"] = "/ Resources / Images / Protector /" + e.FileName; Sevimage (e.FileName, FileUploadGaurdianPic, 2); } // Here I am generating thumbnails, and I am uploading a temporary image on the temporary path, if you do not need it, then delete it. I am only saving the orientation path to the thumbnailline; Private Zero Satellite Image (String Filename, Ajax ControlTool Kit.AnsicFile Upload Uploader, Int Status) {string path = String.Empty; Switch (position) {case1: path = server.mappath ("~ / resources / images / student /"); break; Case 2: Path = Server.MapPath ("~ / Resources / Images / Protector /"); break; } String name = string.opt; String stored path = string.opt; Int intThumbWidth = 100; Int intThumbHeight = 100; // Check this by opening the System.Drawing.Image.GetThumbnailImageAbort myCallBack = New System.Drawing.Image.GetThumbnailImageAbort (Thumbnail Callback) check whether the file is actually a JPEG; // Create Thumbnail Bitmap myBitmap = myBitmap = New Bitmap (Uploader. PostFile.InputStream); ; Bitmap map = new bitmap (uploader. Fill content); // Save thumbnail and assign it to the ThumbUrl parameter System.Drawing.Image myThumbnail = myBitmap.GetThumbnailImage (intThumbWidth, intThumbHeight, myCallBack, IntPtr.Zero); Try {string tempPath = Server.MapPath ("/ Resources / Images / Temporary /"); If (! Directory.Exists (tempPath)) {Directory.CreateDirectory (tempPath); } If (directory.Exists (path)) {name = Path.GetFileName (FileName); StoredPath = Path + name; MyThumbnail.Save (storedPath); Uploader.SaveAs (tempPath + name); } Else {Directory.CreateDirectory (Path); Name = path. GetFileName (filename); StoredPath = Path + name; MyThumbnail.Save (storedPath); Uploader.SaveAs (tempPath + name); }} Hold (Exception pre) {east; }}

And previous, the Javascript function will display that image;

  function uploadComplete (sender, args) {var imgDisplay = $ ("imageGaurdainTemp"); Var img = new image (); Img.onload = function () {imgDisplay.style.cssText = "height: 100px; width: 100px"; ImgDisplay.src = img.src; }; Img.src = "/ Resources / Images / Protectors /" + args.get_fileName (); }   

I hope this helps: D

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -