Accessing Office Clip Board using C#.net - clipboard

I use Visual Studio 2005 to develop a "Windows Service" using c#.net. My code requires to access the MS office Clipboard. But on trying to access the Clipboard class, the debugger throws an error
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."
during the run-time. On checking for the solutions, I found that this could be solved by adding "[STAThread]" before the main method. But on adding this, I get a compilation error
"The type or namespace name 'STAThread' could not be found (are you missing a using directive or an assembly reference?)"
Is it possible to access the clipboard with my current version of .NET(.NET 3.0)?
The main method is in a file titled "program.cs" and the logic is in a file titled "Service.cs". Clipboard is used by Service.cs.
/* Program.cs */
using System.Collections.Generic;
using System.ServiceProcess;
using System.Text;
using System.Media;
using System.Threading;
namespace WindowsService1
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
#if DEBUG
Service1 serv = new Service1();
serv.onDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service1() };
ServiceBase.Run(ServicesToRun);
#endif
}
}
}
/* Service.cs */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Timers;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public void onDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
clear_cb();
}
protected void clear_cb()
{
Clipboard.Clear(); // This is the line where I get the exception
}
protected override void OnStop()
{
// TODO: To clear the back up Database
}
}
}

Related

Trying to establish a connection in xamarin VS 2019

I’m trying to establish a connection with a Web Service already running with Visual Studio 2019 community. The connection is already establish on Visual Studio but when trying to use it I got CS0119 error ‘UsuariosSoap’ is a type, which is not valid int given context.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Net;
using UsuarioWS;
namespace XamarinWSMobile
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void AnadirUsuario(object sender, EventArgs e)
{
//establece la conexion con el web service
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
usuarioWS.GuardarUsuarioAsync(this.Nombre.Text, this.Apellidos.Text,this.Direccion.Text, this.Pueblo.Text, this.ZipCode.Text, this.FechaNac.Text);
}
}
}
That error is telling UsuariosSoap is a Type so this is wrong:
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
In order to use it, you need to create an instance of the service, the UsuariosSoap class, before using it.
Replace the line above with this:
UsuarioWS.UsuariosSoap usuarioWS = new UsuarioWS.UsuariosSoap();
Hope this helps.-

Sensenet does not respond after installation is completed and trying to access URL " http://localhost:xxxx/Root/Sites/Default_site"

I have installed Sensenet Services and Sensenet ECM Webpages packages in my .Net project using Nuget packages and followed the installation steps mentioned in the readme file.
My Global.asax' markup looks like
<%# Application Codebehind="Global.asax.cs" Inherits="SenseNet.Portal.Global" Language="C#" %>
and my Global.asax.cs file looks like
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace SensenetDemoApplication
{
public class MvcApplication : System.Web.HttpApplication
{
public void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
public class Global : SenseNet.Portal.SenseNetGlobal
{
protected override void Application_Start(object sender, EventArgs e, HttpApplication application)
{
try
{
MvcApplication original = new MvcApplication();
original.Application_Start();
base.Application_Start(sender, e, application);
}
catch (Exception )
{
throw;
}
}
}
}
In debug mode the application starts and initializes all components. But when it gets to the implicit code for starting the application
" base.Application_Start(sender, e, application);" the debugger doesn't returns back or no exception is throwing simply the application runs without an output infinitely. Could you please help me what is the issue with my code.
I think the code in your example is more complicated than it should be. You do not have to have your own class that inherits from HttpApplication, sensenet already has one. You only have to inherit your MvcApplication class from the base class above (SenseNet.Portal.SenseNetGlobal) and call the original generated methods after the base app start method call.
See an example here:
MvcApplication class example
This repository contains a few pre-built project templates that include one or more sensenet components (NuGet packages) already installed, we plan to keep these up-to-date.
I'll add the example class here, it is really short:
namespace SnWebApplication
{
public class MvcApplication : SenseNet.Portal.SenseNetGlobal
{
protected override void Application_Start(object sender, EventArgs e, HttpApplication application)
{
base.Application_Start(sender, e, application);
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}

Execution of infinite loop in c exe vs c# exe

I created a c program which has infinite loop.It runs fine.I also created c# program which has infinite loop.While the form ran,latter program process stopped responding.Why does both behaves differently?
Below are the codes
#include<stdio.h>
int main()
{
int i;
for(i=0;i>=10;i++){
printf("%d",i);
}
return 0;
}
c# program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i=10;
while (i > 1)
{
//do nothing
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
My question is how infinite loops work in these two programs?
Your C# program is in a form. Windows expects the form to be able to process events (e.g. telling it to close) but it can't because it's in the infinite loop.
If the infinite loop was in its own thread, or you wrote a C# console application instead of a form-based one, I think it would behave more like your C.

Error during installing selenium on Visual studio 2010

Error: The type or namespace name 'Selenium' could not be found (are you missing a using directive or an assembly reference?)
CODE Generated by the IDE
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTests
{
[TestFixture]
public class Untitled
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.ehow.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheUntitledTest()
{
selenium.Open("/tips_7490061.html");
selenium.Click("//a[contains(text(),'How to Conserve Water Usage')]");
selenium.WaitForPageToLoad("30000");
}
}
}
Have you added the Selenium DLL to the c# project?
I have a basic tutorial available here that should help you through getting started.

Cocoa: PhotoshopImage class and resize

Does anyone knows how i can resize the PhotoshopImage instance?
I don't us the UIImageView because i need to load a lot of images and the PhotoshopImage class handles it better.
Got a real shaky start for you! Photoshop has documentation on using javascript vbscript with photoshop dll's: http://www.adobe.com/devnet/photoshop/scripting.html. These same methods are exposed via COM to C# and I wonder if they're available to Objective-C (RedGate and the vs object browser can help if you dabble with it). Don't cringe at the C# code! The point is photoshop exposes dlls which can be worked with. C# ASP.NET exposes photoshop .dll's via COM. I'm new to objective-c and not a vet at C#! I got this code to work on my windows machine in C#. This code cranks up a web page and fires up my version of photoshop cs3 and goes thru my directory of files and creates an "Adobe image gallery". Good luck to you and post back what you find in objective-c...I think objective-c can run native C and I've seen some documentation of working with photoshop in native C...Shoot some code back either way...I'm a semi newbie so if this wasn't what you meant by Photoshop Image I apologize!
CDUB
PS these are all photoshop methods being exposed, nothing I made up...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GoogleTalkAPILib;
using ps = Photoshop;
using Photoshop;
namespace photoshop
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
Object ob= null;
//works!!!!!!
// co.Application.MakePDFPresentation(oaa,
"C:\Users\Photoshoptryrescl",ob);
//you can also use c# to run a javascript
// co.DoJavaScript("hey.js",e,d );
co.MakePhotoGallery(oab, "C:\\photoshopdump", ob);
}
catch (Exception ex)
{ Trace.Write(ex.Message.ToString()); }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ps = Photoshop;
using Photoshop;
using Microsoft.Win32.SafeHandles;
using Microsoft.Win32;
using Microsoft;
namespace photoshop
{
public delegate void addBlur();
public class Class1 : ApplicationClass, ArtLayer, Document
{
public Class1()
{ }
public void addBlur()
{ }
public void addBlur1(string sa)
{ }
#region ArtLayer Members
public void AdjustBrightnessContrast(int Brightness, int Contrast)
{
throw new NotImplementedException();
}
public void AdjustColorBalance(object Shadows, object Midtones, object Highlights, object PreserveLuminosity)
{
throw new NotImplementedException();
}
public void AdjustCurves(object CurveShape)
{
throw new NotImplementedException();
}
public void AdjustLevels(int InputRangeStart, int InputRangeEnd, double InputRangeGamma, int OutputRangeStart, int OutputRangeEnd)
{
throw new NotImplementedException();
}
public bool AllLocked
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public void ApplyAddNoise(double Amount, PsNoiseDistribution Distribution, bool Monochromatic)
{
throw new NotImplementedException();
}
public void ApplyAverage()
{
throw new NotImplementedException();
}
public void ApplyBlur()
{
// throw new NotImplementedException();
}
public void ApplyBlurMore()
{
throw new NotImplementedException();
}
//etc... these interfaces expose a ton of methods which can be explicity implemented
//this isn't them all

Resources