الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

خطا فى برمجة الجوال

بدأه حاطب في 15 مايو 2009 · 1 رد · 1,355 مشاهدة · في برمجة الأجهزة الكفية والمحمولة بالدوت نيت
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

عندي برنامج المطلوب منة رفع الملف من الجوال الى السيفر بس في خط فى الكود مب عارف حلة

541972326.jpg

وهذا الكود

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;


namespace GPRS
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}


		private CM cm = new CM();
		private ConnectionStatus status = new ConnectionStatus();


		private void button_Connect_Click(object sender, EventArgs e)
		{
			Uri u = new Uri(textBox_URL.Text);

			Guid[] mappedGUIDs = cm.MapURL(u);

			status = cm.Connect(mappedGUIDs[0]);

			if (status == ConnectionStatus.Connected)
				label_Status.Text = "Connection Succeded!";
			else
				label_Status.Text = "Connection Failed : " + status.ToString();
		}

		private void button_ReleaseConnection_Click(object sender, EventArgs e)
		{
			cm.ReleaseCon();
			cm.GetStatus();
			label_Status.Text = cm.ConStatus.ToString();
		}

		public void UploadFile(string localFile, string textBox_URL)
		{
			HttpWebRequest req = (HttpWebRequest)WebRequest.Create(textBox_URL);
			req.Method = "PUT";
			req.AllowWriteStreamBuffering = true;

			// Retrieve request stream and wrap in StreamWriter
			Stream reqStream = req.GetRequestStream();
			StreamWriter wrtr = new StreamWriter(reqStream);

			// Open the local file
			StreamReader rdr = new StreamReader(localFile);

			// loop through the local file reading each line 
			//  and writing to the request stream buffer
			string inLine = rdr.ReadLine();
			while (inLine != null)
			{
				wrtr.WriteLine(inLine);
				inLine = rdr.ReadLine();
			}

			rdr.Close();
			wrtr.Close();

			req.GetResponse();
		}

		public void UploadFileBinary(string localFile, string textBox_URL)
		{
			HttpWebRequest req = (HttpWebRequest)WebRequest.Create(textBox_URL);

			req.Method = "PUT";
			req.AllowWriteStreamBuffering = true;

			// Retrieve request stream 
			Stream reqStream = req.GetRequestStream();

			// Open the local file
			FileStream rdr = new FileStream(localFile, FileMode.Open);

			// Allocate byte buffer to hold file contents
			byte[] inData = new byte[4096];

			// loop through the local file reading each data block
			//  and writing to the request stream buffer
			int bytesRead = rdr.Read(inData, 0, inData.Length);
			while (bytesRead > 0)
			{
				reqStream.Write(inData, 0, bytesRead);
				bytesRead = rdr.Read(inData, 0, inData.Length);
			}

			rdr.Close();
			reqStream.Close();

			req.GetResponse();
		}


		private void uploadButton_Click_1(object sender, EventArgs e)
		{
			UploadFile(localFile.Text, textBox_URL.Text);
		}

		private void uploadBinaryButton_Click(object sender, EventArgs e)
		{
			UploadFileBinary(localFile.Text, textBox_URL.Text);
		}


	}
}

دايم يطلع لى خط فى هذا السطر

// Open the local file
			StreamReader rdr = new StreamReader(localFile);

فا الى عندة فكرة ولا حل لا يبخل بها على

وشكرا

#2

السلام عليكــم ورحمـة الله وبركاتــه ،،

The problem is in the path

run your application in debug mode with a breakpoint in the instruction

streamreader .....

And you will see that the path localFile is not formatted correctly

مواضيع مشابهة