Search Results

Search found 4334 results on 174 pages for 'sender'.

Page 62/174 | < Previous Page | 58 59 60 61 62 63 64 65 66 67 68 69  | Next Page >

  • C#/.NET: TextBox is not 'focused' after a process was initiated

    - by eibhrum
    Hi, I am having a problem after opening the notepad once I click the button "btnSearch". The idea is that once I clicked the button 'btnSearch', the textbox 'txtSearch' should be 'focused' even after a process was initiated/opened outside the main window. Here's my code: private void btnSearch_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Process.Start("notepad"); txtSearch.Focus(); // not working } Any suggestions?

    Read the article

  • Getting a screenshot of a page using .NET - Need help with code

    - by Ender
    I'm writing a specialized crawler and parser for internal use and I require the ability to take a screenshot of a web page in order to check what colours are being used throughout. The program will take in around ten web addresses and will save them as a bitmap image, from there I plan to use LockBits in order to create a list of the five most used colours within the image. To my knowledge it's the easiest way to get the colours used within a web page but if there is an easier way to do it please chime in with your suggestions. Anyway, I was going to use this program until I saw the price tag. I'm also fairly new to C#, having only used it for a few months. Can anyone provide me with a solution to my problem of taking a screenshot of a web page in order to extract the colour scheme? EDIT: Sorry for not getting back to this sooner, but I've been busy with some other things. Anyway, the code seems to work well, but the problem I am having right now is that I am running it within a form, and naturally with Application.Run() being called I cannot run two instances of the same form at once. It recommended Form.showDialog() but that broke everything. Can anyone give me a hand with this code? public static void buildScreenshotFromURL(string url) { int width = 800; int height = 600; using (WebBrowser browser = new WebBrowser()) { browser.Width = width; browser.Height = height; browser.ScrollBarsEnabled = true; // This will be called when the page finishes loading browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(OnDocumentCompleted); //browser.DocumentCompleted += OnDocumentCompleted; browser.Navigate(url); // This prevents the application from exiting until // Application.Exit is called // Application.Run() does not work as it cannot be called twice, recommended form.showDialog() // but still issues Application.Run(); } } public static void OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { // Define size of thumbnail neded int thumbSize = 50; // Now that the page is loaded, save it to a bitmap WebBrowser browser = (WebBrowser)sender; // Code edited from example below to make smaller bitmap and save as PNG using (Graphics graphics = browser.CreateGraphics()) { using (Bitmap bitmap = new Bitmap(browser.Width, browser.Height, graphics)) { Rectangle bounds = new Rectangle(0, 0, bitmap.Width, bitmap.Height); browser.DrawToBitmap(bitmap, bounds); Bitmap thumbBitmap = new Bitmap(bitmap.GetThumbnailImage(thumbSize, thumbSize, thumbCall, IntPtr.Zero)); thumbBitmap.Save("screenshot.png", ImageFormat.Png); handleImage(thumbBitmap); } }

    Read the article

  • how to make IXMLHTTPRequest work over HTTPS, client being WinCE

    - by siddharth
    hi, i am creating a client, which uploads to and dowloads from WinCE client. the code works properly for HTTP but not for HTTPS. Can any one help me about the changes that needs to be done. Code of client on PC : private void btnUpload_Click(object sender, EventArgs e) { try { MSXML2.DOMDocument xmlDOM = new DOMDocumentClass(); xmlDOM.load(txtUpload.Text); MSXML2.IXMLHTTPRequest x = new XMLHTTPClass(); x.open("POST", "http://192.168.1.12/server.asp?cmd=1", false, "", ""); x.send(xmlDOM); string result = x.responseText; if (x.status == 200) { MessageBox.Show(result); MessageBox.Show("upload file successfully"); } else { MessageBox.Show("upload file unsuccessful"); MessageBox.Show(x.status.ToString() + "\n" + x.statusText); } } catch(Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Data); } } private void btnDownload_Click(object sender, EventArgs e) { try { HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://192.168.1.12/server.asp?cmd=2"); WebReq.Method = "GET"; HttpWebResponse WebResp = null; WebResp = (HttpWebResponse)WebReq.GetResponse(); Stream myResponseStream = WebResp.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream); string s = myStreamReader.ReadToEnd(); MessageBox.Show(s); StreamWriter SW; SW = File.CreateText(txtDownload.Text); SW.WriteLine(s); SW.Close(); MessageBox.Show(@"save file at" + txtDownload.Text); myStreamReader.Close(); myResponseStream.Close(); WebResp.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Data); } The client asp page that acts according to the command is : On Error Resume Next Response.Expires = 0 Dim cmd cmd = Request.QueryString("cmd") if cmd = "2" Then Dim xml_dom1 set xml_dom1 = CreateObject("MSXML2.DOMDocument") xml_dom1.load("\Windows\Config.xml") '(Server.MapPath("Config.xml")) Response.Write(xml_dom1.xml) set xml_dom1 = nothing end if if cmd = "1" Then dim xml_dom set xml_dom = CreateObject("MSXML2.DOMDocument") xml_dom.load(request) xml_dom.save("\Windows\Config.xml") set xml_dom = Nothing end if If err.number < 0 Then Response.Write(err.Description) Response.Write(err.number) End If

    Read the article

  • How to solve this issues in URL?

    - by Ayyappan.Anbalagan
    I am doing billing project.i am passing invoice number to another .aspx page. /default.aspx?editid=5 its my url. if i changed my editid no=4 then the records also changes.how to solve this issue?? page1: LinkButton InvoiceEdit = sender as LinkButton; string EditId = InvoiceEdit.CommandArgument.ToString(); Response.Redirect("edit invoice.aspx?EditId=" + EditId); page2: String invoiceId = Request.QueryString["InvoiceId"].ToString();

    Read the article

  • Retrive treeview item

    - by Anu
    Hi, In y treeview i have text,after i seelcted that,i want to retrive that selected item as string and i need to pass this string to various fucntions. I dont know how to get the selected item.I coded like private void treeview1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { TreeViewItem selectedTVI = null; if (treeview1.SelectedItem != null) { selectedTVI = treeview1.Tag as TreeViewItem; } } But selectedTVi shows NULL.What can i do?

    Read the article

  • Auto showing tips and closing popup when lost focus

    - by darkwindkey
    I have two elements: a TextBox, and a Popup, where the popup contains a tree view to show some tips according to text of TextBox. When the textBox got the KeyDown Event, the KeyDown directly executes pup.IsOpen=true to show the popup tips. However, I also want to show the popup tips when the mouse on clicking the TextBox, and auto closing the popups when the mouse click on any place (besides the TextBox and the TreeView in Popup). I have tried some cases but do not works fine. Case1: Add pup.IsOpen=true; in TextBox.PreviewMouseUp, the popup will stay opening, even if I click any other place in the window. Case2: Add pup.IsOpen=true in TextBox.PreviewMouseDown, the popup tips only shows on keep clicking the Mouse. Case3: Using CheckBox with Binding IsChecked to Popup.IsOpen works fine. but the tips is listed according to the content of the TextBox, therefore the checkbox is not editable for user... Here is my code now: <Window x:Class="popUpTesting.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TextBox Name="SearchBox" HorizontalAlignment="Center" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Center" KeyDown="SearchBox_KeyDown" PreviewMouseUp="SearchBox_PreviewMouseUp" /> <Popup Placement="Bottom" AllowsTransparency="True" PopupAnimation="Fade" StaysOpen="false" x:Name="pup" PlacementTarget="{Binding ElementName=SearchBox}" IsOpen="False" > <Grid> <TreeView HorizontalAlignment="Left" Height="200" VerticalAlignment="Top" Width="200"> <TreeViewItem Header="A"> <TreeViewItem Header="A1"/> </TreeViewItem> <TreeViewItem Header="B"></TreeViewItem> <TreeViewItem Header="C"></TreeViewItem> <TreeViewItem Header="D"></TreeViewItem> </TreeView> </Grid> </Popup> </Grid> </Window> and the event functions: private void SearchBox_KeyDown(object sender, KeyEventArgs e) { pup.IsOpen = true; } private void SearchBox_PreviewMouseUp(object sender, MouseButtonEventArgs e) { pup.IsOpen = true; }

    Read the article

  • ASP.Net Checkbox value at postback is wrong?

    - by Duracell
    We have a checkbox that is initially disabled and checked. It is then enabled on the client side through javascript. If the user then unchecks the box and presses the button to invoke a postback, the state of the checkbox remains as checked on the server side. This is obviously undesirable behaviour. Here is an example. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testcb.aspx.cs" Inherits="ESC.testcb" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <script type="text/javascript"> function buttonClick() { var cb = document.getElementById('<%= CheckBox1.ClientID %>'); cb.disabled = false; cb.parentNode.disabled = false; } </script> <div> <asp:CheckBox ID="CheckBox1" runat="server" Checked="true" Enabled="false" /> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="buttonClick(); return false;" /> <asp:Button ID="Button2" runat="server" Text="Button2" OnClick="button2Click" /> </div> </form> </body> </html> And the Server-side code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ESC { public partial class testcb : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void button2Click(object sender, EventArgs e) { string h = ""; } } } So we break at the "string h" line and check the value of CheckBox1.Checked. It is true, even if it is unchecked on the form.

    Read the article

  • ASP.NET AJAX Doesnt Work

    - by Petras
    I have a very simple AJAX example that doesn't work. It is from the Microsoft tutorials on AJAX. When I click on button "Button1" AJAX should execute but the whole page submits. Here is the code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="1111.aspx.cs" Inherits="_1111" %> <%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <p> DropDownList AutoPostBack SelectedIndexChanged EventArgs Sort ... Since you will be using AJAX to process your SelectedIndexChanged event, set the AutoPostBack property of the DropDownList to false. ...</p> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </asp:ScriptManager> <asp:Label ID="label2" runat="server"></asp:Label><br /> <asp:Label ID="label3" runat="server"></asp:Label><br /> <center> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="label1" runat="server"></asp:Label> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button 1" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel></center> </div> </form> </body> </html> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _1111 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { label1.Text = System.DateTime.Now.ToString(); label2.Text = System.DateTime.Now.ToString(); label3.Text = System.DateTime.Now.ToString(); } protected void Button1_Click(object sender, EventArgs e) { label1.Text = System.DateTime.Now.ToString(); } }

    Read the article

  • COMException Problem

    - by Jack Harvin
    Wondering if anyone could help with my problem. Below is the code, and after the code an explination of where the exception is thrown. 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; using System.Web; using WatiN.Core; using System.Threading; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : System.Windows.Forms.Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Thread t = new Thread(createApplications); Settings.AutoStartDialogWatcher = false; t.SetApartmentState(System.Threading.ApartmentState.STA); t.Start(); } private void createApplications() { createApp("username", "password", "Test App", "This is just a test description", "http:/mysite.com"); } private void createApp(String username, String password, String appName, String description, String appUrl) { var currentBrowser = new IE("http://mysite.com/login/php"); currentBrowser.TextField(Find.ById("username")).TypeText(username); currentBrowser.TextField(Find.ById("password")).TypeText(password); currentBrowser.Button(Find.ById("submit")).Click(); currentBrowser.GoTo("http://mysite.com/createmusicapp.php"); currentBrowser.TextField(Find.ById("application_name")).TypeText(appName); currentBrowser.TextField(Find.ById("application_description")).TypeText(description); currentBrowser.TextField(Find.ById("application_url")).TypeText(appUrl); currentBrowser.RadioButton(Find.ById("client_application_desktop_1")).Click(); currentBrowser.RadioButton(Find.ById("client_application_is_writable_1")).Click(); WatiN.Core.Image captchaImage = currentBrowser.Div(Find.ById("recaptcha_image")).Image(Find.ByStyle("display", "block")); Form2 captcha = new Form2(captchaImage.Src); captcha.ShowDialog(); } } } The exception is thrown on this line: currentBrowser.TextField(Find.ById("username")).TypeText(username); BUT, it's thrown when it gets to this line: captcha.ShowDialog(); It logs in, and fills in the app details and Form2 loads fine, but once loaded, after around 2-3 seconds the exception happens. I am wondering if it's anything to do with the threads? But I wouldn't know how to solve it if it was. The complete exception thrown is: The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

    Read the article

  • c#: what is the purpose of wpf vs. winforms [closed]

    - by every_answer_gets_a_point
    i know wpf can be richer-looking, but what is the point of using them if they complicate things so much? for example if i want to do something on form load in wpf i have to through the trouble of writing this: public MyWindow() { Loaded += MyWindow_Loaded; } private void MyWindow_Loaded(object sender, RoutedEventArgs e) { // do work here } whereas in winforms all i do is double click on the form the question is what are the benefits of using wpf over winforms?

    Read the article

  • What information should I log if I detect that my site is under attack?

    - by Abe Miessler
    In the code below if I get into the if statement I can safely say my site is under attack. What information is it a good idea to log? Any recommendations on actions that can be taken to minimize the damage at this point? protected void btn_Search_Click(object sender, EventArgs e) { if(tb_SearchBox.Text.Length > tb_SearchBox.MaxLength) { //What should i log? //What actions should I take? } //Otherwise search }

    Read the article

  • Using the Callback Method on a View in ASP.NET MVC

    - by Tony
    I have a master page with that code: public string CallbackMethod; protected void Page_Load(object sender, EventArgs e) { CallbackMethod = Page.ClientScript.GetCallbackEventReference(this, "message", "Dodanie", "context", true); } /other code here/ then, in the View (which is based on that master page) I need to invoke the CallbackMethod string, but the problem is, the framework firstly renders the View, and then invokes the Page_Load method. As the obvious result, the error appears: the name 'CallbackMethod' does not exist in the current context. How do I fix this?

    Read the article

  • SaveFileDialog problem (C#) (VS2008)

    - by typoknig
    Hi all, I am having an issue with SaveFileDialog for some reason. All I want to do is extract data from a text box line by line and write it to a text file, then save that text file to the desktop. The first bit of code works fine (though it doesn't save to the desktop). The second bit of code is what I want to use, but when it creates the text file the text file is empty. What did I do wrong in my second bit of code? This code works, but it does not save to the desktop and it isn't as nice as the second code. //When the Save button is clicked the contents of the text box will be written to a text file. private void saveButton_Click(object sender, EventArgs e) { int textBoxLines = textBox.Lines.Count(); if (File.Exists(saveFile)) { result = MessageBox.Show("The file " + saveFile + " already exists.\r\nDo you want to replace it?", "File Already Exists!", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { TextWriter tw1 = new StreamWriter(saveFile); for (int i = 0; i < textBoxLines; i++) { tw1.WriteLine(textBox.Lines.GetValue(i)); } tw1.Close(); } if (result == DialogResult.No) { MessageBox.Show("Please move or rename existing " + saveFile + "\r\nBefore attempting to save again.", "Message"); } } else { TextWriter tw2 = new StreamWriter(saveFile); for (int i = 0; i < textBoxLines; i++) { tw2.WriteLine(textBox.Lines.GetValue(i)); } tw2.Close(); } } This code does not work, but it is what I want to use. //When the Save button is clicked the contents of the text box will be written to a text file. private void saveButton_Click(object sender, EventArgs e) { int textBoxLines = textBox.Lines.Count(); Stream saveStream; SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; saveDialog.FilterIndex = 2; saveDialog.RestoreDirectory = true; saveDialog.FileName = (saveFile); saveDialog.InitialDirectory = (Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); if (saveDialog.ShowDialog() == DialogResult.OK) { if ((saveStream = saveDialog.OpenFile()) != null) { StreamWriter tw = new StreamWriter(saveStream); for (int i = 0; i < textBoxLines; i++) { tw.WriteLine(textBox.Lines.GetValue(i)); } saveStream.Close(); } } }

    Read the article

  • scala actor message definition

    - by BenZen
    Do i need to define class for message i want to retrieve on a scala actor? i trying to get this up where am i wrong def act() { loop { react { case Meet = foundMeet = true ; goHome case Feromone(qty) if (foundMeet == true) = sender ! Feromone(qty+1); goHome }}}

    Read the article

  • How to catch exception in the main thread if the exception occurs in the secondary thread?

    - by Ashish Ashu
    How to catch exception in the main thread if the exception occurs in the secondary thread? The code snippet for the scenario is given below: private void button1_Click(object sender, EventArgs e) { try { Thread th1 = new Thread(new ThreadStart(Test)); th1.Start(); } catch (Exception) { } } void Test() { for (int i = 0; i < 100; i++) { Thread.Sleep(100); if (i == 2) throw new MyException(); } } }

    Read the article

  • Apache Email trace

    - by Sergio
    I'm using few PHP scripts for sending Email to website members. Is it possible to see at cPanel WHM mail statistic which PHP script was sent specific email using sendmail function? At section "View Relayers" I can see Time Sent, Message ID, Sender, Destination but not the script that fired this sendmail function.

    Read the article

  • C# - NetworkChangeEventHandler

    - by Andy
    I have small application which catches Network Availability change and its working very fine in client Desktop m/c (which is having XP) But when I tested the same in Vista by disabling the network and enabling it again..the event is not getting triggered. NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged); private void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e) {.....} Does .Net framework 3.5 got any new solution introduced ...

    Read the article

  • ASP.Net 4.0 - Response required in SiteMap building?

    - by Nick Craver
    I'm running into an issue upgrading a project to .Net 4.0...and having trouble finding any reason for the issue (or at least, the change causing it). Given the freshness of 4.0, not a lot of blogs out there for issues yet, so I'm hoping someone here has an idea. Preface: this is a Web Forms application, coming from 3.5 SP1 to 4.0. In the Application_Start event we're iterating through the SiteMap and constructing routes based off data there (prettifying URLs mostly with some utility added), that part isn't failing though...or at least isn't not getting that far. It seems that calling the SiteMap.RootNode (inside application_start) causes 4.0 to eat it, since the XmlSiteMapProvider.GetNodeFromXmlNode method has been changed, looking in reflector you can see it's hitting HttpResponse.ApplyAppPathModifier here: str2 = HttpContext.Current.Response.ApplyAppPathModifier(str2); HttpResponse wasn't used at all in this method in the 2.0 CLR, so what we had worked fine, in 4.0 though, that method is called as a result of this stack: [HttpException (0x80004005): Response is not available in this context.] System.Web.XmlSiteMapProvider.GetNodeFromXmlNode(XmlNode xmlNode, Queue queue) System.Web.XmlSiteMapProvider.ConvertFromXmlNode(Queue queue) System.Web.XmlSiteMapProvider.BuildSiteMap() System.Web.XmlSiteMapProvider.get_RootNode() System.Web.SiteMap.get_RootNode() Since Response isn't available here in 4.0, we get an error. To reproduce this, you can narrow the test case down to this in global: protected void Application_Start(object sender, EventArgs e) { var s = SiteMap.RootNode; //Kaboom! //or just var r = Context.Response; //or var r = HttpContext.Current.Response; //all result in the same "not available" error } Question: Am I missing something obvious here? Or, is there another event added in 4.0 that's recommended for anything related to SiteMap on startup? For anyone curious/willing to help, I've created a very minimal project (a default VS 2010 ASP.Net 4.0 site, all the bells & whistles removed and only a blank sitemap and the Application_Start code added). It's a small 10kb zip available here: http://www.ncraver.com/Test/SiteMapTest.zip Update: Not a great solution, but the current work-around is to do the work in Application_BeginRequest, like this: private static bool routesRegistered = false; protected void Application_BeginRequest(object sender, EventArgs e) { if (!routesRegistered) { Application.Lock(); if (!routesRegistered) RouteManager.RegisterRoutes(RouteTable.Routes); routesRegistered = true; Application.UnLock(); } } I don't like this particularly, feels like an abuse of the event to bypass the issue. Does anyone have at least a better work-around, since the .Net 4 behavior with SiteMap is not likely to change?

    Read the article

  • WPF ListView GridViewColumn Double Click

    - by Kevin
    Hi, I have a WPF ListView that opens a certain window when double clicked on a certain item inside the list view, but I have a problem. When I double click the GridViewColumn, that also opens up a certain window. Is there a way to detect if the sender is a gridviewColumn or a listView item? Thanks

    Read the article

  • LsaAddAccountRights not working for me

    - by SteveL
    Using: Delphi 2010 and the JEDI Windows API and JWSCL I am trying to assign the Logon As A Service privilege to a user using LsaAddAccountRights function but it does not work ie. after the function returns, checking in Group Policy Editor shows that the user still does not have the above mentioned privilege. I'm running the application on Windows XP. Would be glad if someone could point out what is wrong in my code: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, JwaWindows, JwsclSid; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function AddPrivilegeToAccount(AAccountName, APrivilege: String): DWORD; var lStatus: TNTStatus; lObjectAttributes: TLsaObjectAttributes; lPolicyHandle: TLsaHandle; lPrivilege: TLsaUnicodeString; lSid: PSID; lSidLen: DWORD; lTmpDomain: String; lTmpDomainLen: DWORD; lTmpSidNameUse: TSidNameUse; lPrivilegeWStr: String; begin ZeroMemory(@lObjectAttributes, SizeOf(lObjectAttributes)); lStatus := LsaOpenPolicy(nil, lObjectAttributes, POLICY_LOOKUP_NAMES, lPolicyHandle); if lStatus <> STATUS_SUCCESS then begin Result := LsaNtStatusToWinError(lStatus); Exit; end; try lTmpDomainLen := DNLEN; // In 'clear code' this should be get by LookupAccountName SetLength(lTmpDomain, lTmpDomainLen); lSidLen := SECURITY_MAX_SID_SIZE; GetMem(lSid, lSidLen); try if LookupAccountName(nil, PChar(AAccountName), lSid, lSidLen, PChar(lTmpDomain), lTmpDomainLen, lTmpSidNameUse) then begin lPrivilegeWStr := APrivilege; lPrivilege.Buffer := PChar(lPrivilegeWStr); lPrivilege.Length := Length(lPrivilegeWStr) * SizeOf(Char); lPrivilege.MaximumLength := lPrivilege.Length; lStatus := LsaAddAccountRights(lPolicyHandle, lSid, @lPrivilege, 1); Result := LsaNtStatusToWinError(lStatus); end else Result := GetLastError; finally FreeMem(lSid); end; finally LsaClose(lPolicyHandle); end; end; procedure TForm1.Button1Click(Sender: TObject); begin AddPrivilegeToAccount('Sam', 'SeServiceLogonRight'); end; end. Thanks in advance.

    Read the article

  • Linq to sql C# updating reference Tables

    - by Laurence Burke
    ok reclarification I am adding a new address and I know the structure as AddressID = PK and all other entities are non nullable. Now on insert of a new row the addrID Pk is autogened and I am wondering if I would have to get that to create a new row in the referencing table or does that automatically get generated also. also I want to be able to repopulate the dropdownlist that lists the current employee's addresses with the newly created address. static uint _curEmpID; protected void btnAdd_Click(object sender, EventArgs e) { if (txtZip.Text != "" && txtAdd1.Text != "" && txtCity.Text != "") { TestDataClassDataContext dc = new TestDataClassDataContext(); Address addr = new Address() { AddressLine1 = txtAdd1.Text, AddressLine2 = txtAdd2.Text, City = txtCity.Text, PostalCode = txtZip.Text, StateProvinceID = Convert.ToInt32(ddlState.SelectedValue) }; dc.Addresses.InsertOnSubmit(addr); lblSuccess.Visible = true; lblErrMsg.Visible = false; dc.SubmitChanges(); // // TODO: add reference from new address to CurEmp Table // SetAddrList(); } else { lblErrMsg.Text = "Invalid Input"; lblErrMsg.Visible = true; } } protected void ddlAddList_SelectedIndexChanged(object sender, EventArgs e) { lblErrMsg.Visible = false; lblSuccess.Visible = false; TestDataClassDataContext dc = new TestDataClassDataContext(); dc.ObjectTrackingEnabled = false; if (ddlAddList.SelectedValue != "-1") { var addr = (from a in dc.Addresses where a.AddressID == Convert.ToInt32(ddlAddList.SelectedValue) select a).FirstOrDefault(); txtAdd1.Text = addr.AddressLine1; txtAdd2.Text = addr.AddressLine2; txtCity.Text = addr.City; txtZip.Text = addr.PostalCode; ddlState.SelectedValue = addr.StateProvinceID.ToString(); btnSubmit.Visible = true; btnAdd.Visible = false; } else { txtAdd1.Text = ""; txtAdd2.Text = ""; txtCity.Text = ""; txtZip.Text = ""; btnAdd.Visible = true; btnSubmit.Visible = false; } } protected void SetAddrList() { TestDataClassDataContext dc = new TestDataClassDataContext(); dc.ObjectTrackingEnabled = false; var addList = from addr in dc.Addresses from eaddr in dc.EmployeeAddresses where eaddr.EmployeeID == _curEmpID && addr.AddressID == eaddr.AddressID select new { AddValue = addr.AddressID, AddText = addr.AddressID, }; ddlAddList.DataSource = addList; ddlAddList.DataValueField = "AddValue"; ddlAddList.DataTextField = "AddText"; ddlAddList.DataBind(); ddlAddList.Items.Add(new ListItem("<Add Address>", "-1")); } OK I am hoping that I did not include too much code. I would really appreciate any other comments about I could otherwise improve this code in any other ways also.

    Read the article

  • Running Network Application on port Server side give me error how can i solve it?

    - by Phsika
    if i run Server App. Exception occurs: on Dinle.Start() System.Net.SocketException - Only one usage of each socket address (protocol/network address/port) is normally permitted How can i solve this error? Server.cs 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; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; namespace Server { public partial class Server : Form { Thread kanal; public Server() { InitializeComponent(); try { kanal = new Thread(new ThreadStart(Dinle)); kanal.Start(); kanal.Priority = ThreadPriority.Normal; this.Text = "Kanla Çalisti"; } catch (Exception ex) { this.Text = "kanal çalismadi"; MessageBox.Show("hata:" + ex.ToString()); kanal.Abort(); throw; } } private void Server_Load(object sender, EventArgs e) { Dinle(); } private void btn_Listen_Click(object sender, EventArgs e) { Dinle(); } void Dinle() { // IPAddress localAddr = IPAddress.Parse("localhost"); // TcpListener server = new TcpListener(port); // server = new TcpListener(localAddr, port); //TcpListener Dinle = new TcpListener(localAddr,51124); TcpListener Dinle = new TcpListener(51124); try { while (true) { Dinle.Start(); Exception is occured. Socket Baglanti = Dinle.AcceptSocket(); if (!Baglanti.Connected) { MessageBox.Show("Baglanti Yok"); } else { TcpClient tcpClient = Dinle.AcceptTcpClient(); if (tcpClient.ReceiveBufferSize 0) { byte[] Dizi = new byte[250000]; Baglanti.Receive(Dizi, Dizi.Length, 0); string Yol; saveFileDialog1.Title = "Dosyayi kaydet"; saveFileDialog1.ShowDialog(); Yol = saveFileDialog1.FileName; FileStream Dosya = new FileStream(Yol, FileMode.Create); Dosya.Write(Dizi, 0, Dizi.Length - 20); Dosya.Close(); listBox1.Items.Add("dosya indirildi"); listBox1.Items.Add("Dosya Boyutu=" + Dizi.Length.ToString()); listBox1.Items.Add("Indirilme Tarihi=" + DateTime.Now); listBox1.Items.Add("--------------------------------"); } } } } catch (Exception ex) { MessageBox.Show("hata:" + ex.ToString()); } } } }

    Read the article

  • remove default.aspx from a request

    - by b0x0rz
    i am trying to remove default.aspx from any request that might have it. protected void Application_BeginRequest(object sender, EventArgs e) { HttpContext context = HttpContext.Current; string url = context.Request.Url.ToString(); // remove default.aspx if (url.EndsWith("/default.aspx", StringComparison.OrdinalIgnoreCase)) { url = url.Substring(0, url.Length - 12); } context.Response.Redirect(url); } gives an error: **too many redirects occurred trying to open...** what can i change to make it work? thnx

    Read the article

< Previous Page | 58 59 60 61 62 63 64 65 66 67 68 69  | Next Page >