473,657 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error in sending file

4 New Member
hi i have following code to send file and its giving file io error

Expand|Select|Wrap|Line Numbers
  1. namespace client_server
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             IPAddress ip = IPAddress.Parse("127.0.0.1");
  8.             TcpListener tcp = new TcpListener(ip, 1234);
  9.             tcp.Start();
  10.             Console.WriteLine("server started");
  11.             while (true)
  12.             {
  13.                 Socket socket = tcp.AcceptSocket();
  14.                 if (socket.Connected)
  15.                 {
  16.                     CHandler clH = new CHandler(socket);
  17.                     Thread t = new Thread(new ThreadStart(clH.Task));
  18.                     t.Start();
  19.                 }
  20.             }
  21.         }
  22.     }
  23.  
  24.  
  25.     class CHandler
  26.     {
  27.         Socket socket;
  28.         public CHandler(Socket s) { socket = s; }
  29.         public void Task()
  30.         {
  31.             string path = "C:/";
  32.             NetworkStream net = new NetworkStream(socket);
  33.             StreamReader nIn = new StreamReader(net);
  34.             StreamWriter nOut = new StreamWriter(net);
  35.             string fName = nIn.ReadLine();
  36.             path = path + fName;
  37.  
  38.             try
  39.             {
  40.                 StreamReader fIn = new StreamReader(path);
  41.                 string nextLine;
  42.                 Console.WriteLine("sending file");
  43.                 nextLine = fIn.ReadLine();
  44.                 while (nextLine != null)
  45.                 {
  46.  
  47.                     nOut.WriteLine(nextLine);
  48.                     nOut.Flush();
  49.                     nextLine = fIn.ReadLine();
  50.                 }
  51.                 Console.WriteLine("file sent");
  52.                 fIn.Close();
  53.                 net.Close();
  54.                 nOut.Close();
  55.                 socket.Close();
  56.             }
  57.             catch { Console.WriteLine("file IO error"); }
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63.  
  64. namespace clientside
  65. {
  66.     class Program
  67.     {
  68.         static void Main(string[] args)
  69.         {
  70.             Console.Write("enter the file name");
  71.             string name = Console.ReadLine();
  72.             TcpClient serSocket;
  73.             try
  74.             {
  75.                 serSocket = new TcpClient("127.0.0.1", 1234);
  76.             }
  77.             catch
  78.             {
  79.                 Console.WriteLine("Failed to connect");
  80.                 return;
  81.             }
  82.             NetworkStream net = serSocket.GetStream();
  83.             StreamWriter sOut = new StreamWriter(net);
  84.             StreamReader sIn = new StreamReader(net);
  85.  
  86.             try
  87.             {
  88.                 sOut.WriteLine(name);
  89.                 sOut.Flush();
  90.                 string nextLine = sIn.ReadLine();
  91.                 while (nextLine != null)
  92.                 {
  93.                     Console.WriteLine(nextLine);
  94.                     nextLine = sIn.ReadLine();
  95.                 }
  96.                 sIn.Close();
  97.                 net.Close();
  98.             }
  99.             catch
  100.             {
  101.                 Console.WriteLine("error reading from server");
  102.             }
  103.  
  104.  
  105.             Console.ReadKey();
  106.         }
  107.     }
  108. }
Mar 26 '10 #1
7 1824
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 26 '10 #2
tlhintoq
3,525 Recognized Expert Specialist
On what line is the error?
What exactly is the full error?
Mar 26 '10 #3
koneyji
4 New Member
can't find the exactly where the error is?
i think the error is somewhere here
Expand|Select|Wrap|Line Numbers
  1.  try
  2.             {
  3.                 StreamReader fIn = new StreamReader(path);
  4.                 string nextLine;
  5.                 Console.WriteLine("sending file");
  6.                 nextLine = fIn.ReadLine();
  7.                 while (nextLine != null)
  8.                 {
  9.  
  10.                     nOut.WriteLine(nextLine);
  11.                     nOut.Flush();
  12.                     nextLine = fIn.ReadLine();
  13.                 }
  14.                 Console.WriteLine("file sent");
  15.                 fIn.Close();
  16.                 net.Close();
  17.                 nOut.Close();
  18.                 socket.Close();
thanks for the reply
Mar 27 '10 #4
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 27 '10 #5
tlhintoq
3,525 Recognized Expert Specialist
To have this break on the exact line producing the code you need to make a change to your settings. Next time you debug this, Visual Studio will stop softly on any exception when it is Thrown instead of only when it goes unhandled.

Debug menu
Exceptions
Check on "CLR"

Mar 27 '10 #6
koneyji
4 New Member
thank you

the error is in
StreamReader fIn = new StreamReader(pa th);

it says
{"Access to the path 'D:\\datafiles\ \data' is denied."}

i think it is a folder privacy issue..
Mar 30 '10 #7
tlhintoq
3,525 Recognized Expert Specialist
Well there ya go. Glad we could help you track down the exact nature of the problem: You don't have permissions in that folder or to that item. Mystery solved.
Mar 30 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5025
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
7
4531
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. //UploadForm.asp <FORM NAME="InputForm" ACTION="UploadAction.asp" METHOD="POST" enctype=multipart/form-data> <input type="file" name="fileName"> //etc ... </FORM>
2
4753
by: Roald Oines | last post by:
Hi, I'm working on converting several of my Access 97 databases to Access 2002 format (the company's changing from NT 4 to XP and updating Office at the same time), and this one has me stumped. As a performance enhancer, I use VBA code (transfertext) to export the results of a query (usually 20-30 thousand rows with a few dozen fields of customer information) to the user's temp folder as a text file and then link to it using a text file...
14
3882
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the maxRequestLength parameter of the <httpRuntime> section and that works as expected. What I want is to enforce a max file size but haven't been able to trap the error thrown when the file is too large and that's where I could use some help.
1
1565
by: JamesB | last post by:
Hello I am in the process of making a small app that will be used by the slightly more, er, IT challenged customers we have to send us their databases via FTP. Going ok, but when I come to writing the data stream it is terminating with "unable to write data to the transport connection tcpclient" Adding a quick messagebox on the exception, I am getting: "An established connection was aborted by the software in your host machine".
7
6859
by: news | last post by:
Recently our mail from our e-commerce site has been rejected by AOL due to an IP block because someone was using our PHP scripts to send spam. Well, I got that fixed. But our legitimate auto-generated e-mails are getting "deferred" by AOL now with an error: Deferred: Bad file descriptor I can't find anything on their support site about this, nor Googling. Any ideas?
2
2999
by: Cesar | last post by:
Hello, I've developed a .NET C# web service; which has one method named, let's say, upload_your_data. This method has one parameter ( string your_data). The value that this parameter will actually have is the content of a XML document. This data will be processed and check for a well-formed xml document and will be validated against a XSD. Before putting my code, let me go on and explain the whole situation. This web method is invoked...
1
2751
by: Alexander Higgins | last post by:
>>Thanks for the response.... Point Taken but this is not the case. Thus, if a person writes a text file on her or his computer and does not use UNICODE to save it, the current code page is used. If this file is given to someone with some other current codepage, the file is not displayed correctly. Simply converting the file to Unicode will make the data display properly. When performing the encoding process the encoding will escape...
3
5121
by: nvr | last post by:
Hi all I am doing the socket programming for the client side. but the code is not compiling and i am getting the below error ./Clientsend.c: line 11: syntax error near unexpected token `(' ./Clientsend.c: line 11: `int main()' Code: #include <stdio.h> #include <stdlib.h>
3
2393
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is not authorized" i have configure smtp server put 127.0.0.1 ip in relay and also put 127.0.0.1 ip in connection. using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing;
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.