473,506 Members | 17,176 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't Copy to Clipboard

SAL
I have the following VB.net Class/Function that I call from an ASP.net page:

Public Class MyTestClass
Public Function embedHyperlink(ByVal fileID As Integer, ByVal fileName
As String) As String

'Create a New Instance of the HyperLink Control
Dim createHyperLink As New System.Web.UI.WebControls.HyperLink

'Create an Instance of the ClipBoard Object
Dim objClipboard As System.Windows.Forms.Clipboard

Dim sBuildHyperLink As String

Try
'Set the Properties of the HyperLink Control
createHyperLink.ID = "EmbeddedHyperLink"
createHyperLink.NavigateUrl =
"http://www.someDomain.com/docPage.aspx?x=" & fileID
createHyperLink.Text = fileName

'Build HTML HyperLink String
sBuildHyperLink = "<a href=" & createHyperLink.NavigateUrl & ">"
& createHyperLink.Text & "</a>"

'Write HyperLink to Clip Board
objClipboard.SetDataObject(sBuildHyperLink, True)

Return sBuildHyperLink

Catch ex As Exception
Throw
Finally
createHyperLink = Nothing
objClipboard = Nothing
sBuildHyperLink = Nothing
End Try
End Function
End Class

When I get to the line "objClipboard.SetDataObject(sBuildHyperLink, True)",
that writes to the Windows Clipboard I get the following error and I don’t
know why:

Server Error in '/MyTestWeb' Application.
________________________________________
The current thread must set to Single Thread Apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Threading.ThreadStateException: The current thread
must set to Single Thread Apartment (STA) mode before OLE calls can be made.
Ensure that your Main function has STAThreadAttribute marked on it.

Can someone tell me what I’m doing wrong?

Thanks

Feb 8 '06 #1
3 3704
> I have the following VB.net Class/Function that I call from an ASP.net page:

Public Class MyTestClass
Public Function embedHyperlink(ByVal fileID As Integer, ByVal fileName
As String) As String

'Create a New Instance of the HyperLink Control
Dim createHyperLink As New System.Web.UI.WebControls.HyperLink

'Create an Instance of the ClipBoard Object
Dim objClipboard As System.Windows.Forms.Clipboard

Dim sBuildHyperLink As String

Try
'Set the Properties of the HyperLink Control
createHyperLink.ID = "EmbeddedHyperLink"
createHyperLink.NavigateUrl =
"http://www.someDomain.com/docPage.aspx?x=" & fileID
createHyperLink.Text = fileName

'Build HTML HyperLink String
sBuildHyperLink = "<a href=" & createHyperLink.NavigateUrl & ">"
& createHyperLink.Text & "</a>"

'Write HyperLink to Clip Board
objClipboard.SetDataObject(sBuildHyperLink, True)

Return sBuildHyperLink

Catch ex As Exception
Throw
Finally
createHyperLink = Nothing
objClipboard = Nothing
sBuildHyperLink = Nothing
End Try
End Function
End Class

When I get to the line "objClipboard.SetDataObject(sBuildHyperLink, True)",
that writes to the Windows Clipboard I get the following error and I don’t
know why:

Server Error in '/MyTestWeb' Application.
________________________________________
The current thread must set to Single Thread Apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Threading.ThreadStateException: The current thread
must set to Single Thread Apartment (STA) mode before OLE calls can be made.
Ensure that your Main function has STAThreadAttribute marked on it.

Can someone tell me what I’m doing wrong?

Thanks


What clipboard do you expect to copy to?
This looks like a portion of a code-behind file, which is executed on
the server. At the most you can write to the clipboard of the *server*,
not that of the *client*! And even that is problematic: only the
"aspnet" user would be able to access that particular clipboard item (I
think).

Hans Kesting
Feb 8 '06 #2
SAL
Good point Hans. I do want it to copy to the Clipboard where the client is
and not the Server. Here is the code that calls my function now, but I still
get the same error:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim test As New MyTestClass

'Create an Instance of the ClipBoard Object
Dim objClipBoard As System.Windows.Forms.Clipboard

'Write HyperLink to Clip Board

objClipBoard.SetDataObject((test.CreateHyperlink(C Int(TextBox1.Text),
TextBox2.Text)), True)

End Sub

"Hans Kesting" wrote:
I have the following VB.net Class/Function that I call from an ASP.net page:

Public Class MyTestClass
Public Function embedHyperlink(ByVal fileID As Integer, ByVal fileName
As String) As String

'Create a New Instance of the HyperLink Control
Dim createHyperLink As New System.Web.UI.WebControls.HyperLink

'Create an Instance of the ClipBoard Object
Dim objClipboard As System.Windows.Forms.Clipboard

Dim sBuildHyperLink As String

Try
'Set the Properties of the HyperLink Control
createHyperLink.ID = "EmbeddedHyperLink"
createHyperLink.NavigateUrl =
"http://www.someDomain.com/docPage.aspx?x=" & fileID
createHyperLink.Text = fileName

'Build HTML HyperLink String
sBuildHyperLink = "<a href=" & createHyperLink.NavigateUrl & ">"
& createHyperLink.Text & "</a>"

'Write HyperLink to Clip Board
objClipboard.SetDataObject(sBuildHyperLink, True)

Return sBuildHyperLink

Catch ex As Exception
Throw
Finally
createHyperLink = Nothing
objClipboard = Nothing
sBuildHyperLink = Nothing
End Try
End Function
End Class

When I get to the line "objClipboard.SetDataObject(sBuildHyperLink, True)",
that writes to the Windows Clipboard I get the following error and I don’t
know why:

Server Error in '/MyTestWeb' Application.
________________________________________
The current thread must set to Single Thread Apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Threading.ThreadStateException: The current thread
must set to Single Thread Apartment (STA) mode before OLE calls can be made.
Ensure that your Main function has STAThreadAttribute marked on it.

Can someone tell me what I’m doing wrong?

Thanks


What clipboard do you expect to copy to?
This looks like a portion of a code-behind file, which is executed on
the server. At the most you can write to the clipboard of the *server*,
not that of the *client*! And even that is problematic: only the
"aspnet" user would be able to access that particular clipboard item (I
think).

Hans Kesting

Feb 8 '06 #3
"SAL" <SA*@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Can someone tell me what I'm doing wrong?


You're trying to get your server to write to your clients' clipboard - not
going to happen.

You can manipulate the clipboard in ASP.NET, but only through JavaScript,
and the text you're trying to copy to your clients' clipboard will need to
be sent down to the client as part of the JavaScript code...

http://www.google.com/search?sourcei...clipboard+copy
Feb 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1357
by: Jarrad | last post by:
I can't copy an ASP Project between two different computers for development work. The virtual directory structure I need is different for the second one... can't even change the virtual structure...
2
1672
by: jake | last post by:
How can I copy a file securely (encryption) from remote computers easily (Mac and Linux) to my Win 2000 Server once a day?
1
1689
by: paul fpvt2 | last post by:
How can I copy an html file to a local drive ? For example: I would like to copy www.mywebsite.mypage.htm to c:\inetput\wwwroot\mydir\mypage.htm, can I do that ? Thanks.
3
1406
by: thaar al_taiey | last post by:
hi their, How can i copy data in MS-SQL 2000 from one table to another with different charactristic? thanks *** Sent via Developersdex http://www.developersdex.com ***
0
1703
by: chawes40 | last post by:
I have an aspx.cs with a listbox to display the results, but I can't copy or paste from this box. What other box can I use that will display my results and allow to to cut or copy from the box?
4
1428
by: realjacky | last post by:
How can i copy a table to a new table(structure and data) with primary key remain i have try to use Select * into table from old_table However, i dont have any primary key which old_table have...
7
3866
by: ankush143 | last post by:
How can i copy the output of graphics mode program?? i have made various programs in graphics....and i want their output on the MS-Word so how can i copy it??
7
2384
by: ahmed222too | last post by:
how can i copy a text file and paste it in a specific path by VB6 code another question how can i create afolder in a specific path by VB6 thank you
0
1249
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I am trying to install IIS but ran into the following problem. I have installed xp service pack 2 and am trying to install IIS using the add windows component feature but get the error (setup...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.