Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good day to all. I just want to ask for help, in file transfer code I've found on google it successfully send the file to another pc but unable to include the file name and the file format of the file. Example "molly" and "eric" are sending file to each other, they can successfully send file to each other but the main problem is the file that they received does not have any information or even a file name, but still the file is not corrupted. It is hard for both of them to identify what kind of file they receive since the file information is not included in the transmission. in order for theme to open the file, they first ask the sender about the information of the file and its file format then the one who receive the file will now manually edit the file and put its the correct file extension. how can i solve this problem? if i send a file with a file name world.doc i want the receiver to receive it as world.doc, so that they can easily open the file. hoping for some help. it could improve my programming skills level.
Posted
Updated 28-Jan-12 7:50am
v2
Comments
OriginalGriff 28-Jan-12 12:45pm    
Without knowing any more than that, we can't help.
What you have told us so far is like phoning the garage and saying "I've broken down, come and fix it" and putting the phone down.
The garage doesn't have a clue who you are, where you are, or what your problem is, so they can't move.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Hello dear you can send the file information with the file.
first you get all file attributes and transfer it with file
 
Share this answer
 
Comments
Member 7812734 29-Jan-12 6:40am    
i already get the information of the file, and i don't know how to include it in the transmission, i have a sample code here can you help me locate where should i put the information so that it can be included in the transmission?

private void btnbrowse_Click(object sender, EventArgs e)
{
OpenFileDialog Dlg = new OpenFileDialog();
Dlg.Filter = "All Files (*.*)|*.*";
Dlg.CheckFileExists = true;
Dlg.Title = "Choose a File";
Dlg.InitialDirectory = @"C:/";
if (Dlg.ShowDialog() == DialogResult.OK)
{
SendingFilePath = Dlg.FileName;

}
FileInfo fileinf = new FileInfo(Dlg.FileName);
filename = Path.GetFileName(Dlg.FileName);
txtFileinfo.Text = Convert.ToString(fileinf);
}
public void SendTCP(string M, string IPA, Int32 PortN)
{
byte[] SendingBuffer = null;
TcpClient client = null;

NetworkStream netstream = null;
try
{
client = new TcpClient(IPA, PortN);

netstream = client.GetStream();
FileStream Fs = new FileStream(M, FileMode.Open, FileAccess.Read);
int NoOfPackets = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Fs.Length) / Convert.ToDouble(BufferSize)));

int TotalLength = (int)Fs.Length, CurrentPacketLength; //counter = 0
for (int i = 0; i < NoOfPackets; i++)
{
if (TotalLength > BufferSize)
{
CurrentPacketLength = BufferSize;
TotalLength = TotalLength - CurrentPacketLength;
}
else
CurrentPacketLength = TotalLength;
SendingBuffer = new byte[CurrentPacketLength];
Fs.Read(SendingBuffer, 0, CurrentPacketLength);
netstream.Write(SendingBuffer, 0, (int)SendingBuffer.Length);

}


Fs.Close();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900