简体   繁体   中英

System.Windows.Forms.Clipboard works on desktop, but does not work on IIS

I have a small module, which is looking for an image in the clipboard and if it is there, displays it on the page. This works great in my desktop, but never gets into System.Windows.Forms.Clipboard.ContainsImage() when hosted on IIS. Any concept that beats the purpose, like a windows clipboard cannot be used by server side application?

        if (System.Windows.Forms.Clipboard.ContainsImage())
        {
            img = System.Windows.Forms.Clipboard.GetImage();
            imgBytes = imageToByteArray(img);
            string imgString = Convert.ToBase64String(imgBytes, 0, imgBytes.Length);                
            clipBoardImg.ImageUrl = "data:image/jpeg;base64," + imgString;
            clipBoardImg.Visible = true;
        }

If you try to access the clipboard on IIS, you try to access it on the server , not on the client. This will most definitely fail server-side too since you don't have a screen in your server process (you are not user-interactive).

The thing you should do is convert this code to something client side (javascript for example), which is hard since you can't just access the clipboard from the clients browser.

I think it is (almost) impossible to get this implemented. Would the use of a input type=file help you? Or a drag-drop surface ? This seems the better options to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM