|
How an unauthorised IP thru my lisitning port destroy my system?
|
|
|
|
|
hi
in a hash tabele i got key as modem numbers and value is an incrementing int values .how can i know which key value is the highest or lowest in c#?
|
|
|
|
|
Hi,
the keys and the values are available as an ICollection in Hashtable.Keys and Hashtable.Values,
so you can figure it out yourself. Same for Dictionaries.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, February 20, 2009 12:04 AM
modified on Sunday, June 12, 2011 8:24 AM
|
|
|
|
|
can somebody help me with a c# code to get the highest int value in a hash table..plzz
|
|
|
|
|
this means you have a Hashtable and the keys are INT?
you may get all the keys of a HT, by using Keys property, just create a function that returns the MAX from keys array.
Calin
|
|
|
|
|
I have been trying to parse the Directory list into usable information.
For example if I am given the following:
-rw-r--r-- 1 ftp ftp 87040 Feb 17 23:46 Test_test Resume_Full.doc
The problem is how to know what is what. I can't parse/split based on a space " " because what happens is the date is seperated on spaces as well as the file names.
Can anybody help me?
Code Information below: In the code below the method "ExecuteCommand" just gets the response from the server.
------------------------------CODE BLOCK----------------------------------
Socket l_ClientDataSocket = null;
int l_iDataPort;
TcpListener l_FTPListener = null;
Byte[] l_bRecvData = new Byte[5120];
int l_iBufferLimit = 5119;
FileStream l_fsOutFile = null;
BinaryWriter l_fbOutFile = null;
string l_strCommand = "";
StringCollection l_strOutput = new StringCollection();
int l_iRetval = 0;
l_FTPListener = new TcpListener(0);
l_FTPListener.Start();
IPEndPoint pt = (IPEndPoint)l_FTPListener.LocalEndpoint;
l_iDataPort = pt.Port;
string l_strPortParams = GetPortParameters(l_iDataPort);
string l_strPortCommand = "PORT " + l_strPortParams + "\r\n";
l_iRetval = ExecuteCommand(l_strPortCommand, ref l_strOutput);
l_strCommand = "LIST " + l_strCurrDir + "\r\n";
l_iRetval = ExecuteCommand(l_strCommand, ref l_strOutput);
Thread.Sleep(500);
if (l_FTPListener.Pending())
{
l_ClientDataSocket = l_FTPListener.AcceptSocket();
}
l_ClientDataSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, RecvTimeOut);
l_ClientDataSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, SendTimeOut);
l_bRecvData.Initialize();
l_strOutput = new StringCollection();
l_iRetval = 0;
string l_strTemp = "";
Thread.Sleep(1000);
for (; l_ClientDataSocket.Available > 0; )
{
l_bRecvData.Initialize();
l_iRetval = l_ClientDataSocket.Receive(l_bRecvData, l_iBufferLimit, 0);
l_strTemp = Encoding.ASCII.GetString(l_bRecvData, 0, l_iRetval);
Thread.Sleep(400);
}
if (l_FTPListener != null)
{
l_FTPListener.Stop();
l_FTPListener = null;
}
modified 13-Feb-19 21:02pm.
|
|
|
|
|
I'm having a really strange problem with trying to access a SharePoint site via code.
I have an application that is using the SharePoint object model, like this
using (SPSite site = new SPSite(SiteIP))
The code is running on one server(SP is on this server) but now it needs to be moved to another server. Since the SiteIP is read from a config file I thought, no problem, change the IP and it should work. However, every time I try I get the FileNotFoundException. No matter what machine I try running it on I get the same exception.
To make it even more strange if I run this code on another box but use the IP of the site that is currently work I get the same exception.
A couple of articles pointed to a problem about giving the AppPool identity permissions in SQL Server, but that didn't help.
This is really baffling me. Anyone have some ideas?
only two letters away from being an asset
|
|
|
|
|
i want to count using c# how many times a particular methos is called...can somebody help me wit that!!!
|
|
|
|
|
Try using a static variable inside the function that you increment every time it is called!!!!!!!!
|
|
|
|
|
Hi
I'm looking for update only records which has been changed. usually, when u use SqlDataAdapter class, u can update existing records and send changes to database like this :
sqlDataAdapter1.Update(dataTable);
dataTable.AcceptChanges();
but i don't use SqlDataAdapter, i use SqlCommand.ExecuteNonQuery.
does anyone has the same experience with update only changed records ?
thanks
|
|
|
|
|
One presumes you use a proc to update each row. Inspect the rowstate of the datatable to identify rows that have changed or are new.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft
ok, my another question (main question) is how to only refresh records in datagridview which has been changed ?
(for example, when user open one records in details form and update data then click ok, that specific record refresh in my datagridview)
thanks
|
|
|
|
|
There are a number of ways to do this, again assumes you have a proc that saves 1 record at a time.
You can identify the record by filtering the defaultview on the datatable on rowstate and process the results. This can be done anytime before acceptchanges.
Change your method to accept a datarow, you already know the row, it was identified when you entered the detail form. This can then be done on the save of the detail form.
I actually use a listview/grid for browsing on the main form and when the user selects something I pop a detail form, passing the ID (or 0 for insert). On the way out of the detail form I save the row (completely different table used by the detail only). The main form refreshes the list datatable based on the dialogresult of the detail form. Trick being to limit your main form list to a reasonable size, 2-300 records only. I know this is expensive in database reads but I never have data sitting on the client that has not been saved and the speed has been more than acceptable for decades now.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why the IDictionary interface is inherited from ICollection & IEnumerable
public interface IDictionary : ICollection, IEnumerable
When the ICollection interface is already inherited from IEnumarable???
|
|
|
|
|
It is an explicit statement by the author or an error of omission.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
I am using axWebBrowser.
How can i get html code of page that in browser now?
|
|
|
|
|
Hi,
you should have a look at the WebBrowser class, and its Document property.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:25 AM
|
|
|
|
|
What can i do with this property? Hw can i get source of page in browser?
|
|
|
|
|
Try DocumentText[^] property of WebBrowser class. It will give you the HTML for the current page displayed in webbrowser.
|
|
|
|
|
axWebBrowser has not DocumentText property.
What can i do with Document property?
|
|
|
|
|
I'm learning c# and would love some help with an issue that I'm having. I've created a little app that copies some images from one place to another. I've just started playing with Threading and have moved the copy to a thread in a different class. My issue is with updating a label on the main form with the text of what I'm copying. Here's a quick snippet of my code...
FrmMain.cs
private void btnCopyImages_Click(object sender, System.EventArgs e)
{
updateStatusLabel("Running...");
GetInitialSettings();
Thread CopyThread = new Thread(new ThreadStart(CopyImages));
CopyThread.Start();
updateStatusLabel("Done.");
}
private void CopyImages() {
Files oFiles = new Files();
oFiles.sMediaDir = txtMediaDir.Text;
oFiles.sBuildDir = txtBuildDir.Text;
oFiles.sMediaFoldersFilter = txtFilterMediaFolders.Text;
oFiles.bIsBMW = bIsBMW;
oFiles.GetFolders(txtMediaDir.Text);
rchTxtBoxFoldersCopied.Text = rchTxtBoxFoldersCopied.Text + "\n\n" + oFiles.sFoldersCopied;
oFiles = null;
}
public void updateStatusLabel(string sText) {
lblStatus.Text = sText;
lblStatus.Refresh();
}
files.cs
private void updateLabel(string sText) {
FrmMain oFrmMain = new FrmMain();
oFrmMain.updateStatusLabel(sText);
oFrmMain = null;
}
public void GetFolders(string sDir) {
try
{
string sBuildFolder = "";
string[] folders = Directory.GetDirectories(sDir);
bool bFilteredFolder = false;
foreach(string folder in folders)
{
if (sMediaFoldersFilter == "All")
{
bFilteredFolder = true;
}
else {
string[] sFolderFilters = sMediaFoldersFilter.Split(new char[] {','});
foreach (string filterFolder in sFolderFilters)
{
if (folder.IndexOf(filterFolder) > -1)
{
bFilteredFolder = true;
break;
}
}
}
if (bFilteredFolder) {
string sFolder = folder.Substring(folder.LastIndexOf("\\") + 1);
switch (sFolder.ToLower())
{
case "colourized" :
...
CopyFiles(folder,sBuildFolder);
...
}
break;
case ...
break;
default:
break;
}
}
bFilteredFolder = false;
GetFolders(folder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to read directories\n" + err.Message + "\n";
}
}
private void CopyFiles(string sMediaDir, string sBuildDir) {
try
{
string[] files = Directory.GetFiles(sMediaDir);
foreach (string file in files)
{
updateLabel("copying : " + folder.ToString());
string name = Path.GetFileName(file);
string dest = Path.Combine(sBuildDir,name);
File.Copy(file,dest,true);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to copy files\n" + err.Message + "\n";
}
}
Any help for a newbie would be much appreciated .
|
|
|
|
|
Call BeginInvoke on the method you want to call.
BeginInvoke(new MethodInvoker(
delegate() { updateStatusLabel("Done."); })
);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
sorry still not quite getting it . It's the ability to update with the file that I'm copying that I'm having the issues with, which is in a different class file.
<br />
private void updateLabel(string sText) {<br />
FrmMain oFrmMain = new FrmMain();<br />
<br />
BeginInvoke (new MethodInvoker(<br />
delegate() {oFrmMain.updateStatusLabel(sText);}<br />
));<br />
<br />
oFrmMain = null;<br />
}<br />
?!?
|
|
|
|
|
OK - here's a working sample...
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Shown += new EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, EventArgs e)
{
Thread CopyThread = new Thread(new ThreadStart(DoStuff));
CopyThread.Start();
}
void UpdateLabel(string text)
{
label1.Text=text;
}
void DoStuff()
{
BeginInvoke(new MethodInvoker(
delegate() { UpdateLabel("I'm doing it..."); })
);
Thread.Sleep(5000);
BeginInvoke(new MethodInvoker(
delegate() { UpdateLabel("Done!"); })
);
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
clearly it's a friday, because I'm still not getting it . I've posted the code from files.cs which is loaded by the main form (FrmMain.cs)...
using System;
using System.IO;
using System.Threading;
namespace BMWImageCopier
{
public class Files
{
public Files()
{
}
public string sMediaDir = "";
public string sBuildDir = "";
public string sFoldersCopied = "";
public string sMediaFoldersFilter = "";
public bool bIsBMW = true;
private void CheckFolderExists(string sFolder) {
try
{
if (!Directory.Exists(sFolder)) {
Directory.CreateDirectory(sFolder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to create build directories\n" + err.Message + "\n";
}
}
private void updateLabel(string sText) {
FrmMain oFrmMain = new FrmMain();
BeginInvoke (new MethodInvoker(
delegate() {oFrmMain.updateStatusLabel(sText);}
));
Thread.Sleep(1000);
oFrmMain = null;
}
public void GetFolders(string sDir) {
try
{
string sBuildFolder = "";
string[] folders = Directory.GetDirectories(sDir);
bool bFilteredFolder = false;
foreach(string folder in folders)
{
if (sMediaFoldersFilter == "All")
{
bFilteredFolder = true;
}
else {
string[] sFolderFilters = sMediaFoldersFilter.Split(new char[] {','});
foreach (string filterFolder in sFolderFilters)
{
if (folder.IndexOf(filterFolder) > -1)
{
bFilteredFolder = true;
break;
}
}
}
if (bFilteredFolder) {
string sFolder = folder.Substring(folder.LastIndexOf("\\") + 1);
CheckFolderExists(sBuildFolder);
CopyFiles(folder,sBuildFolder);
}
bFilteredFolder = false;
GetFolders(folder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to read directories\n" + err.Message + "\n";
}
}
private void CopyFiles(string sMediaDir, string sBuildDir) {
try
{
string[] files = Directory.GetFiles(sMediaDir);
foreach (string file in files)
{
updateLabel("copying : " + sMediaDir.ToString());
string name = Path.GetFileName(file);
string dest = Path.Combine(sBuildDir,name);
File.Copy(file,dest,true);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to copy files\n" + err.Message + "\n";
}
}
}
}
p.s. thanks for bearing with me .
|
|
|
|