|
I'm having problem in the Server Side;
How do i receive the file? and if i need the extension of the file, i have to send it with the client? and then how do i retrieve it? Thanks
else if (data.StartsWith("$UploadFile"))
{
}
|
|
|
|
|
You can create your own communication protocol. Let's say that the client sends a message to the server telling him that he will upload a file with a specified extension and size. The server sends back an acknowledge message and the the client sends the file.
Concerning the server. If you know the exact size of the file then you can do something like:
byte[] buffer = new byte[size];
client.Receive(buffer);
If you do not know the size of the file then you can write a sequence that reads data from the network in packets let's say 1024 long, like this:
ArrayList list = new ArrayList();
byte[] buffer = new byte[1024];
int read = 0;
int length = 0;
while ((read = client.Receive(buffer) != 0)
{
length += read;
list.Add(buffer);
buffer = new byte[1024];
if (read < 1024)
break;
}
At the end of this code you have inside the array list the entire file stored in 1024 length byte , arrays. After this just extract the byte arrays from the array list, like this.
buffer = new byte[length];
byte []temp = null;
int k = 0;
for (int i = 0 ; i < list.Count ; i++)
{
temp = (byte[])list[i];
for (int j = 0 ; j < temp.Length ; j++)
byte[k++] = temp[j];
}
Hope it helps.
Do your best to be the best
|
|
|
|
|
Ok, here is the Code, what's wrong?
//Client Side
FileStream fstream = File.Open(txtPathFile.Text, FileMode.Open);
byte[] buffer = new byte[fstream.Length];
fstream.Read(buffer, 0, buffer.Length);
fstream.Close();
Send("$UploadFile," + NameFileUpload.Remove(0, NomeFileUpload.ToString().LastIndexOf(@"\")).Remove(0, 1) + "," + buffer.Length + "|");
s.Send(buffer);
//Server Side
else if (data.StartsWith("$UploadFile"))
{
string[] b = data.Split(',');
string nameFile = b[1];
string size = b[2];
byte[] buffer = new byte[Int32.Parse(size)];
sock1.Receive(buffer);
File.WriteAllBytes(@"C:\" +nameFile, buffer);
}
|
|
|
|
|
Ok, here is the Code, what's wrong?
//Client Side
FileStream fstream = File.Open(txtPathFile.Text, FileMode.Open);
byte[] buffer = new byte[fstream.Length];
fstream.Read(buffer, 0, buffer.Length);
fstream.Close();
Send("$UploadFile," + NameFileUpload.Remove(0, NomeFileUpload.ToString().LastIndexOf(@"\")).Remove(0, 1) + "," + buffer.Length + "|");
s.Send(buffer);
//Server Side
else if (data.StartsWith("$UploadFile"))
{
string[] b = data.Split(',');
string nameFile = b[1];
string size = b[2];
byte[] buffer = new byte[Int32.Parse(size)];
sock1.Receive(buffer);
File.WriteAllBytes(@"C:\" +nameFile, buffer);
}
|
|
|
|
|
Please someone can help me?
|
|
|
|
|
my application shows an agent when it load
i would like when i right click on this agent it shows context menue
how can i do this
thank u
MD_NADA
|
|
|
|
|
I have just finished reading a book on C# and I would like to submit a review for it, but I can't find a link, is it the same as for submitting an article link?
|
|
|
|
|
Hello,
I am a noob to C# and would like to know the best method of parsing HTML. Here is an example of what I will be doing a lot of.
I would like to get the following variables
strVis = Detroit
intVisScore = 4
strHome = N.Y. Yankees
intHomeScore = 3
strInning = Final
strBoxScore = http://www.usatoday.com/sports/scores106/106278/MLB725547.htm
If you have something generic w/ good documentation I should be ok w/ that . I like learning the HOW.
Thanks!
Ryan
|
|
|
|
|
You can use a regular expression to parse the string.
As a lot of your example doesn't show up in the forum (as you haven't used the Ignore HTML feature), I can't really make a meaningful example from it. Here is an example from MSDN:
string text = "One car red car blue car";
string pat = @"(\w+)\s+(car)";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
Match m = r.Match(text);
int matchCount = 0;
while (m.Success)
{
Console.WriteLine("Match"+ (++matchCount));
for (int i = 1; i <= 2; i++)
{
Group g = m.Groups[i];
Console.WriteLine("Group"+i+"='" + g + "'");
CaptureCollection cc = g.Captures;
for (int j = 0; j < cc.Count; j++)
{
Capture c = cc[j];
System.Console.WriteLine("Capture"+j+"='" + c + "', Position="+c.Index);
}
}
m = m.NextMatch();
}
---
b { font-weight: normal; }
|
|
|
|
|
Could you enlighten me to the ignore HTML?
Thanks
|
|
|
|
|
You don't ignore the HTML, you use it to identify the information that you want.
If you have the string "...something...<table><tr><td>some info</td></tr></table>...something...", you can use the pattern "<table><tr><td>([^<]+)</td></tr></table>" to get the information.
---
b { font-weight: normal; }
|
|
|
|
|
Hi
I have I a class that inherits from TabConrol called MyControl. I have a class that inherits from TabPage called MyTabPage, as below:
(heavily simplified)
class MyTabControl:TabControl<br />
{<br />
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs ke)<br />
{<br />
(this.SelectedTab as MyTabPage).PanelContained.KDown(ke);<br />
base.OnKeyDown(ke);<br />
}<br />
}<br />
class MyTabPage : TabPage<br />
{<br />
private MyPanel panelContained;<br />
public MyPanel PanelContained{<br />
get { return panelContained; }<br />
set { panelContained = value; }<br />
}<br />
}
How can I override SelectedTab to return a MyTabPage? If I add a MyTabPage and change the panelcontained property, this is null again when I convet it back from SelectedTab.
Seeing as it inherits from TabControl is there a nice way to make it so that I can convert it back into a MyTabPage without losing the added property?
cheeers
|
|
|
|
|
thepersonof wrote: How can I override SelectedTab to return a MyTabPage?
You can't change the return type or the method parameter types in an overload.
thepersonof wrote: Seeing as it inherits from TabControl is there a nice way to make it so that I can convert it back into a MyTabPage without losing the added property?
<br />
TabControl tabs = new MyTabPage();
Since tab control does not have the PanelContained property you will not beable to use it in tabs
unless its cast back up to MyTabPage. Even though the compatible TabControl contains a MyTabPage the PanelContained property will not be exposed. You will have to do this.
<br />
((MyTabPage)tabs).PanelExposed<br />
█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██
|
|
|
|
|
Thank you. I can't manage to make the method you suggest work, does anyone have any other suggestions?
thanks
|
|
|
|
|
i have a folder inclodes some files
how can i read the file name from this folder
thankis for help
MD_NADA
|
|
|
|
|
You can use DirectoryInfo and FileInfo Class and then use getfiles method of directory ojbect to get all the files inside a particular directory. You can also use to to get a particular kind of file
DirectoryInfo dir = new DirectoryInfo(@"d:\skypak\text");<br />
FileInfo[] bmpfiles = dir.GetFiles("*.txt");
|
|
|
|
|
hello
how can i raise an event explicitly using coding for exemple i want to simulate the clicking in a tabpage of the tabcotrol so that it will be showed to the user
thank you! hope that understand what i mean !!
|
|
|
|
|
Mahhouraaaaaa wrote: how can i raise an event explicitly using coding for exemple i want to simulate the clicking in a tabpage of the tabcotrol so that it will be showed to the user
To explicitly raise an event in C# you just call the event as it were a method. You first must check to see if it is null. If it were null then there are no registered methods to that event and an exception will be thrown.
if(Clicked != null)
Clicked();
Your deal with the tab page control is more difficult. If I understood you correctly you want to fire an event of a control from the outside. You will have to send it the ?WM_MOUSECLICK? event, to do that you will need to inject that event into the message queue of Windows itself. You will need to use the native Windows API to do that. There may be other ways, but I am currently unaware of them.
█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██
|
|
|
|
|
Hi.
How can I get the real time of a mp3 file in milisecond ?
Best wishes
|
|
|
|
|
I have to change some of my logic based on the error returned by a code. I have to first try to do a simple insert in a table. If it throws a error then i will have to change the statement(update) and again try the insert. How can i do this. Sorry if i hv posted the question in the wrong discussion board. It may be a quesiton of c# also
|
|
|
|
|
I assume that you expect an error because the record already exists? Then do it the other way arond; first try the update and check how many records were updated. If the record didn't exist the number of records is zero, and you know that you have to make an insert instead.
If you are using MS SQL Server, you can do this in a stored procedure:
create procedure DoSomeSetting
@SomeId int,
@SomeValue somedatatype
as
update DaTable
set Something = @SomeValue
where SomeId = @SomeId
if @@rowcount = 0 begin
insert into DaTable (Something)
values (@SomeValue)
end
---
b { font-weight: normal; }
|
|
|
|
|
hi
i have this code in VB and i want to Convert this code to C# but i don't know VB. Please Convert this code
To C# :
Dim nextLine As Int32
Call PrintGridHeaderLine(e)
Dim StartOfpage As Integer = _CurrentPrintGridLine
For nextLine = _CurrentPrintGridLine To Min((_CurrentPrintGridLine + RowsPerPage(_PrintFont,
e.Graphics)), CType(_DataGrid.DataSource, System.Data.DataTable).DefaultView.Count)
Call PrintGridLine(e, nextLine)
Next
Thanks ..
|
|
|
|
|
Int32 nextLine;
PrintGridHeaderLine(e);
int StartOfpage = _CurrentPrintGridLine;
for (int nextLine = _CurrentPrintGridLine; nextLine <= Min((_CurrentPrintGridLine + RowsPerPage(_PrintFont, e.Graphics)), ((System.Data.DataTable)(_DataGrid.DataSource)).DefaultView.Count); nextLine++) {
PrintGridLine(e, nextLine);
}
Aashutosh kumar
|
|
|
|
|
Hi,
I send mail thru C# code. During execution it throws
following error.
Unhandled Exception: System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 of
fset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpReplyReader.ReadLine()
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Sendmail.Main()
You only have to do a very few things right in your life so long as you don't do too many things wrong.
Vivek.S
|
|
|
|
|
IIS is installed in your PC or not. I think ,System.Net.Mail.SmtpClient.Send user virtual SMTP if you not specify Explicitly .
Check Virtual SMTP under IIS is running or not.If not then run Virtual SMTP.
Then you can send mail successfully.
Regards
rajesh
|
|
|
|