Copy text to clibboard

I have a webapp that pushes email addresses to Outlook (if installed) for the user. If the user does not use Outlook I want to put the email addresses to the clipboard so they can paste it into whatever email client they are using.

I'm having an issue with the Clipboard object... VB.net is not recognizing it. Either I'm missing a reference / Imports statement or this functionality is not available for a web app.

Ideas?
md0333Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nathan BoveSoftware EngineerCommented:
In a web application, all clipboard manipulation must be done on the client.  This typically means it must be done in javascript.  Currently, there is very little support for programmatic clipboard manipulation with javascript since most users would not want to have their browser hijack their clipboard.  Internet explorer has built in support for clipboard manipulation, but none of the other browsers do.

The following article has some information about clipboard manipulation:
http://stackoverflow.com/questions/400212/how-to-copy-to-clipboard-in-javascript
0
Todd GerbertIT ConsultantCommented:
If you create a "mailto:someaddress@somedomain.com" URL and direct the client's browser to that URL, it should automatically open whatever their default mail client is with the "To:" field already filled out.

On an unrelated note, I'm curious as to how you manage to manipulate Outlook from a web app?  I'd seen another similar question and thought it couldn't be done (maybe it was your question)...

(Remember that everything you write in VB.Net, in a web app, runs on the server, not the client - so if you have a button on a web page and in that button's Click event handler you start Outlook, you'll be starting Outlook on the server, not on the computer being used to view your web page)
0
md0333Author Commented:
tgerbert: Well, not sure about that. I do have a question on here for that.

Check if User has Outlook

What I wanted to do was check if user had outlook... and if they did, push the email addresses to to BCC field. If not, put them to the clipboard. I'm interested in your option for creating the "mailto:" url. How would I do that? I need to put the emails in the BCC field of the users default email client.

Here is the code I (thought) I had working for the Outlook stuff...

    Protected Sub ImageForward_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageForward.Click

        Dim bInstalled As Boolean = False

        Try
            Dim TheApp As String = "Outlook.Application"

            Dim oApp As Object = CreateObject(TheApp)
            bInstalled = True
            oApp = Nothing
        Catch
            bInstalled = False
            'MsgBox("Not Installed")
            'MessageBox.Show("Office Application not installed!", "Office Installed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try

        If bInstalled = True Then
            EmailTest()
        Else
            Dim emailstring As String = getEmails()
            'create popup with list of emails user can copy
        End If

    End Sub

    Private Sub EmailTest()

        Dim emailstring As String = getEmails()

        ' Create an Outlook application object instance.
        Dim oApp As Outlook._Application
        oApp = New Outlook.Application()

        ' Create a new MailItem.
        Dim oMsg As Outlook._MailItem
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
        oMsg.Display()
        oMsg.Subject = ""
        oMsg.Body = ""

        oMsg.BCC = emailstring

        ' Clean up
        oApp = Nothing
        oMsg = Nothing
    End Sub

    Private Function getEmails() As String

        Dim emailstring As String = ""
        Dim i As Integer = 0
        Dim chk As CheckBox = Nothing

        For Each item As GridDataItem In RadGrid1.MasterTableView.Items

            chk = CType(item("SelectColumn").Controls(0), CheckBox)

            If chk.Checked = True Then
                If i = 0 Then
                    emailstring = item("Email").Text.ToString()
                    i = 1
                Else
                    emailstring += ";" & item("Email").Text.ToString()
                End If
            End If

        Next

        getEmails = emailstring

    End Function
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

md0333Author Commented:
@tgerbert

I think I got it

        Dim emailstring As String = getEmails()
        System.Diagnostics.Process.Start("mailto:?bcc=" & emailstring)

0
Nathan BoveSoftware EngineerCommented:
None of that code will work.  You are performing all of that processing on the server.  That will only check if the server has outlook installed, not the client.

0
md0333Author Commented:
OK... so then if I do this in Javascript then it should work???

document.write( "<a href='mailto:?bcc=" + emailstring+ "'></A>" );
0
Todd GerbertIT ConsultantCommented:
Yes, JavaScript would be the way to go.  You can also use ClientScript.RegisterScriptBlock to have some javascript added to your page on-the-fly, which will be run when the page loads on the client:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
	Private Sub SendMailButton_Click(ByVal sender As Object, ByVal e As EventArgs)
		Dim emailString As String = "bob@domain1.com;user@domain2.com"
		
		Dim javaScript As String = "document.location.href='mailto:?bcc=" & emailString & "';"

		ClientScript.RegisterClientScriptBlock(Me.GetType(), "MailToScript", javaScript, True)
	End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
		<asp:Button ID="SendMailButton" runat="server" text="Send Mails" OnClick="SendMailButton_Click" />
    </div>
    </form>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nathan BoveSoftware EngineerCommented:
That will work, as long as the variable "emailstring" is declared on the client.
0
md0333Author Commented:
This is what I ended up doing (javascript) and it looks like it's working like a charm! Thanks!!

            function InsertMailToTag() {

                var emailstring = getEmails();
                
                emailWindow = window.open("about:blank", "a", "width=400,height=200,menubar=no,toolbar=no, status=no, location=no");
                with (emailWindow.document) {
  
                    writeln('<html><head><title>FI-Traxx</title><scr' + 'ipt>self.focus();self.moveTo(200,200);</scr' + 'ipt></head>');
                    writeln('<body bgcolor=#202020 link=#74ac42 vlink=#df7e2a alink=#df7e2a>');
                    writeln('<font face=Arial size=2 color=#ffffff>');
                    writeln('<IMG SRC="Images/fitraxxsplashdkBGMedium.png" WIDTH="170" BORDER="0" HEIGHT="47" HSPACE="10" VSPACE="5" ALIGN=left></IMG>');
                    writeln('<br><br><br><br>Click on the link below to add the selected Email addresses.<br><br>');
                    writeln("<a href='mailto:?bcc=" + emailstring + "'>FI-Traxx: Create Email Campaign</A>");
                    writeln('</font>');
                    writeln('</body></html>');
                }

            }

            function getEmails() {

                var grid = $find("<%=RadGrid1.ClientID %>");
                var MasterTable = grid.get_masterTableView();
                var email;

                var selectedRows = MasterTable.get_selectedItems();
                for (var i = 0; i < selectedRows.length; i++) {
                    var row = selectedRows[i];
                    var cell = MasterTable.getCellByColumnUniqueName(row, "Email")
                    if (i == 0)
                        email = cell.innerHTML
                    else
                        email += ";" + cell.innerHTML
                }

                return email;

            }

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.