|
Took me one search in Google to find this[^].
|
|
|
|
|
|
|
Good Morning,
i need your help
let say i want to write a program to adjust one side of a rectangle
with a track bar how can i do that?
thank you
|
|
|
|
|
hi I am getting an error message: Connot implicitly type 'void' to 'string'
here is the code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] strings = { "man", "bites", "mad", "dog" };
dataTextBox.Text = (Permute(strings, Output));
strings[0] = indexTextBox.Text;
strings[1] = indexTextBox.Text;
strings[2] = indexTextBox.Text;
strings[3] = indexTextBox.Text;
}
private void Output(T[] permutation)
{
string data;
data = dataTextBox.Text;
foreach (T item in permutation)
{
dataTextBox.Text = Convert.ToString (item);
}
}
public static void Permute(T[] items, Action output)
{
Permute(items, 0, new T[items.Length], new bool[items.Length], output);
}
private static void Permute(T[] items, int item, T[] permutation, bool[] used, Action output)
{
for (int i = 0; i < items.Length; ++i)
{
if (!used[i])
{
used[i] = true;
permutation[item] = items[i];
if (item < (items.Length - 1))
{
Permute(items, item + 1, permutation, used, output);
}
else
{
output(permutation);
}
used[i] = false;
}
}
}
}
|
|
|
|
|
The reason you are seeing this is because you are trying to assign the output from Permute to the Text property. Permute is a void property, so it cannot return anything.
|
|
|
|
|
Hi what come I do to fixe that
|
|
|
|
|
Return a string value where you have it set to void and actually set it to a meaningful value. This is basic stuff, you should be able to do this already.
|
|
|
|
|
|
Below code works well for printing PDF when we have physical file.
But when we have bytes[] then it will not work. Is there a way we can print bytes[] to printer without showing the print dialog box.
private static void PrintPDF(string FileToPrint)
{
PrinterSettings setting = new PrinterSettings();
var printerName = setting.PrinterName;
ProcessStartInfo info = new ProcessStartInfo(FileToPrint);
info.Verb = "Print";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
}
There is a Microsoft Knowledge base article on this particular problem. Here in the article they send byte[] to the printer using Winspool API of Windows OS. but i don't feel it is optimized for web.
http://support.microsoft.com/kb/322091
|
|
|
|
|
What all this has with the Web?
The code you show us here is part of the server side, means it print on the printer connected to the server? It may looks like working correctly while in debug environment, but will surprise you after publishing? Or do you mean to post out all the printed documents later on the week?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
The code given works well with physcial files
I meant the KB article that code i dont feel is optimized
|
|
|
|
|
It seem that you didn't read or understood what I've wrote...
That code - and your code too - can not be, and need not be optimized to the web as it runs on the server!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Since it runs on server my only concern is when i run it to print too many pdf t slows down when multiple requests are hit.
If there a better way of printing bytes[] to printer
|
|
|
|
|
It is acceptable that printing will slow down with much request (print queue is full), but I have a strong feeling that you do ot know what are you doing here.
Let see an example. Code Project has 'Terms of Service' page stuffed with legal do and don't do. Let imagine that you had a print button on this page. What would happened if on every click on that button a copy of that 'Term of Service' was printed in Toronto, Canada? What Code Project staff should do with all that prints? And what the CPian who asked to print will do without that important paper?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
even though it runs on server but the printer it picks is local to system and not related to server.
what i was asking was is there a better way of doing this instead of using interop's
|
|
|
|
|
Quote: the printer it picks is local to system You are kidding, right?
How on earth the server knows about locally installed printers!!! Imagine that you are browsing a site that hosted on a server in the UK, should that server know anything about your hardware setup and installed drivers in you office in India?! Think about it!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
nitin_ion wrote: but i don't feel it is optimized for web. Of course it isn't; it is for use in desktop applications.
|
|
|
|
|
so is there a way of doing it efficiently on web [printing bytes directly to printer]
|
|
|
|
|
Not directly. What you would have to do is implement an addon for the web browser and control the printing from that (oh, and you'd have to take into account the OS that the website was browsing as well). This isn't a trivial task, and a lot of organisations would bar this control from being installed.
|
|
|
|
|
You can't do it using that code. It's that simple.
That code is written to launch the application that knows how to edit the file and then tells that application to print the file that is passed to it.
This technique will NOT work with an array of bytes because you have no way of getting those bytes to the application that will actually handle the printing operation.
You cannot do what you want and most certainly can't do it from ASP.NET code running on the server.
|
|
|
|
|
Hi
please need urgent help , i am try to resart windows services , using a dropdownlist to choose the particular service, each time i choose the particular service and click restart button i get the error : (Particular service stopped)
public partial class Homepage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FillServiceName();
}
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//Label1.Text = DropDownList1.SelectedIndex.ToString();
//Label1.Text = DropDownList1.SelectedIndex.ToString();
}
public void ServiceRestart(string nameofservice)
{
//Get the name of the service from the Web.config
// string nameofservice = ConfigurationManager.AppSettings["service1"];
ServiceController sv = new ServiceController(nameofservice);
//Get service timeout from App.Config file
int timeinmilliseconds = int.Parse(ConfigurationManager.AppSettings["timeinmilliseconds"].ToString());
try
{
if (sv.Status.Equals(ServiceControllerStatus.Running) && sv.CanStop)
{
int ms1 = Environment.TickCount;
int ms2;
TimeSpan timeout = TimeSpan.FromMilliseconds(timeinmilliseconds);
try
{
sv.Stop();
sv.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
//Console.WriteLine("Service " + nameofservice + " stopped");
Label2.Text = "Services " + nameofservice + " stopped";
ms2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(timeinmilliseconds - (ms2 - ms1));
}
catch
{
Label2.Text = "Services " + nameofservice + "failed to stoped";
}
try
{
sv.Start();
Label2.Text = "Services" + nameofservice + "started";
}
catch
{
Label2.Text = "Services" + nameofservice + "failed to start";
}
sv.WaitForStatus(ServiceControllerStatus.Running, timeout);
//Console.WriteLine("Service " + nameofservice + " started");
//Label2.Text="Services" + nameofservice + "started";
}
else
{
sv.Start();
//Console.WriteLine("Service " + nameofservice + " started");
Label2.Text = "Services" + nameofservice + "started";
}
}
catch (Exception e)
{
//Console.WriteLine("An error has occured: " + e.StackTrace);
//Label2.Text = "Services" + nameofservice + "stopped";
Label2.Text = "An error has occured: " + e.Message;
//Re-start the service but with a longer timeout period
//ServiceRestartAgain(nameofservice);
}
}
//Another service
public void ServiceRestartAgain(string nameofservice1)
{
//Get the name of the service from the Web.config
//string nameofservice1 = ConfigurationManager.AppSettings["service1"];
ServiceController sv1 = new ServiceController(nameofservice1);
int timeinmilliseconds1 = int.Parse(ConfigurationManager.AppSettings["timeinmilliseconds2"].ToString());
try
{
if (sv1.Status.Equals(ServiceControllerStatus.Running) && sv1.CanStop)
{
int ms11 = Environment.TickCount;
TimeSpan timeout1 = TimeSpan.FromMilliseconds(timeinmilliseconds1);
sv1.Stop();
sv1.WaitForStatus(ServiceControllerStatus.Stopped, timeout1);
//Console.WriteLine("Service " + nameofservice1 + " stopped");
Label2.Text="Service " + nameofservice1 + "stopped";
int ms22 = Environment.TickCount;
timeout1 = TimeSpan.FromMilliseconds(timeinmilliseconds1 - (ms22 - ms11));
sv1.Start();
sv1.WaitForStatus(ServiceControllerStatus.Running, timeout1);
//Console.WriteLine("Service " + nameofservice1 + " started");
Label2.Text="Service " + nameofservice1 + "started";
}
else
{
sv1.Start();
//Console.WriteLine("Service " + nameofservice1 + " started");
Label2.Text = "Service " + nameofservice1 + " started";
}
}
catch (Exception e)
{
string stacktrace = e.StackTrace;
//Console.WriteLine("An error has occured in restarting the service again: " + stacktrace);
Label2.Text = e.Message;
//Send mail to e-channels support(In the body of the mail put the stacktrace after adding the message. This is for tracking purposes.
// MailEChannelsSupport(stacktrace);
}
}
public void FillServiceName()
{
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ATMrestartserviceConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Service", con);
cmd.ExecuteNonQuery();
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataSet dats = new DataSet();
adap.Fill(dats);
DataTable dt = new DataTable();
dt = dats.Tables[0];
ListItem lstitem = new ListItem();
lstitem = new ListItem();
lstitem.Text = "Select Service";
lstitem.Value = "s";
drpservice.Items.Add(lstitem);
foreach (DataRow datR in dt.Rows)
{
lstitem = new ListItem();
lstitem.Text = datR["Service"].ToString();
lstitem.Value = datR["Service"].ToString();
drpservice.Items.Add(lstitem);
}
con.Close();
}//end try
catch (Exception ex)
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = (string)Session["Uname"];
name=name.Replace(".", " ");
name=name.ToUpper();
ServiceRestart(drpservice.SelectedValue.ToString());
//string connectionString = "";
string connectionString = "Data Source=172.27.4.227;Initial Catalog=ATMrestartservice;User ID=sa;Password=Wema123";
//string connectionString = "Data Source=172.27.4.227;Initial Catalog=ATMrestartservice;User ID=sa";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Details ([Login Name],Date,[Service started]) VALUES ('" + name + "' ,'" + DateTime.Now + "', '" + drpservice.Text + "')";
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
}
}
}
}
|
|
|
|
|
I hope that's not your real sa password that you've just published on a public forum!
Also, applications should NEVER connect using the sa user. You should always create and use a specific user which only has the permissions required by your application.
Your code in Button1_Click is susceptible to SQL Injection[^]. You should be using parameterized queries instead.
Most of the code you've posted doesn't appear to have anything to do with the problem your having. It's also not particularly easy to read, because you haven't formatted it - either use the "code" button on the toolbar, or wrap the code in <pre>...</pre> tags.
And finally, unless you've modified your AppPool to run as a user with local administrator privileges - which would be a very bad idea! - it won't have permission to restart services.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hai All,
I am facing one problem in my website i am having one default.aspx page its not inheriting master page what i need when i open my site it will expire after 6mins for me whats happening for every pages its working fine every page is inheriting master page but this default.aspx is not inheriting master page so when i open default.aspx and doing something also its showing time out.so now i want to stop master page session time in this defult.aspx how to do.here i dont want to inherit master page and recreate bcz if i inherit master page so many issues will come so other than any solution is there plz tel me its urgent
|
|
|
|
|
Member 10641698 wrote: plz tel me its urgent No. Find some consultants whom you will have to pay for such premium services.
|
|
|
|