Save images on the clipboard to a file from ASP.NET

This piece of code is a 'proof of concept for a larger project, the completed project will grab images from the clipboard using ASP.NET (think: POs, Credit apps, signed delivery tickets) and save them. 

This code saves to the file system (on the client, not the web server), but the production code will save to a SQL table. 

 

Imports System.Threading
Imports System.Windows.Forms
 
Partial Class utilities_DocAttach
    Inherits System.Web.UI.Page
 
    Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
 
        Dim cbThread As New Thread(New ThreadStart(AddressOf CopyToClipboard))
        cbThread.SetApartmentState(ApartmentState.STA)
        cbThread.Start()
        cbThread.Join()
 
    End Sub
 
    Sub CopyToClipboard()
        If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
            Dim oDataObj As System.Windows.Forms.IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
 
            If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
                Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
                'To Save as Bitmap
                oImgObj.Save("c:\temp\Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
                'To Save as Jpeg
                oImgObj.Save("c:\temp\Test.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
                'To Save as Gif
                oImgObj.Save("c:\temp\Test.gif", System.Drawing.Imaging.ImageFormat.Gif)
            End If
        End If
 
    End Sub
End Class

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences