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

رفع ملف من Windows Application

مغلق
بدأه ayman_krosh في 9 فبراير 2008 · 7 رد · 1,189 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم:

أنا متعود على رفع الملفات الخاصة بموقعي ، سواء ملفات pdf او صور ... إلخ من صفحة ويب عن طريق اداة ال/ upload الاعتيادية، ولكني أريد الآن ان ارفعها من خلال نموذج يعمل عندي على الجهاز اي windows application ( desktop application ) وليس upload عادي من صفحة ويب ، أرجوا اعطائي مثال على هذا ... وجزاكم الله خير .

#2

ليش مافي رد...

:angry:

#3

ليش معصب مابدنا نرد .... :resentful:

انا عابمزح

اهلا اخي

من أجل التحميل والرفع نستخدم الكلاس WebClient

على كل حال شوف هالمقالة:

In this tutorial you will know how to download a file from a web site and upload a file to a web site through c# project. 

The System.Net namespace contain most of the .NET base class that deal with networking from perspective of the client. The System.Net namespace is generally concerned with Higher-level operations for example download and upload files and making requests using the HTTP and other protocols. 

The WebClient Class

If you want to do is carry out a fairly simple operation such as requesting a file from a particular URL, Then you will probably find easiest .NET class to use is System.Net.WebClient. This class is extremely high-level class Designed to perform basic operations with only one or two commands 

Downloading Fiels:

There are two ways of downloading a file from a web site using WebClient, depending on whether we want to save the file, or process the contents of the directly within your application. If we simply want to save the file then we should call the DownloadFile() method takes two parameters, The URL from where we want to retrieve the file, and the file name ( or path) that we want to save the file to. 
WebClient Client = new WebClient ();
Client.DownloadFile("http://www.csharpfriends.com/Members/index.aspx", " index.aspx");


More commonly, your application will want to process the data retrieved from the web site. In order to do this, you use the OpenRead () method, Which returns a stream reference. You can then simply retrieve the data from the stream. 
WebClient Client = new WebClient ();
Stream strm = Client.OpenRead ("http://www.csharpfriends.com/Members/index.aspx");


The following code will demonstrate the WebClient.OpenRead () method.

In this case we will simply display the contents of the downloaded data in list box.

We create the project as standard Windows C# application, and a list box called listbox1, in which we will display the contents of the downloaded file. We make the following changes to the constructor of the main form. 
public form1()
{
	InitializeComponent();

	System.Net.WebClient Client = new WebClient();
	Stream strm = Client.OpenRead("http://www.csharpfriends.com");
	StreamReader sr = new StreamReader(strm);
	string line;
	do
	{
		line = sr.ReadLine();
		listbox1.Items.Add(line);
	}
	while (line !=null);
	strm.Close();
}


Updating Files

The webClient class also features UploadFile() and UploadData() methods. The diffrence between them is that UploadFile() uploads a specified file given the file name, While UploadData() uploads binary data, which is supplied as an array of bytes: 
WebClient  Client = new WebClient();
Client.UploadFile("http://www.csharpfriends.com/Members/index.aspx", 
	 "c:\wesiteFiles\newfile.aspx");

byte [] image;

//code to initialise image so it contains all the binary data for some jpg file
client.UploadData("http://www.csharpfriends.com/Members/images/logocc.jpg", image);


In this way we can download and upload a file through c# project Try to upload files to yours web sites and download files. 

I think now you all understand how to upload and download files using c#.

تم تعديل هذه المشاركة بواسطة محمد سماقية في 9 فبراير 2008 في 14:00

-----------------------------------------------------------------------------------------------------------------------------





 

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

Mohammad Sonaiea
 

#4

أخ محمد سماقية ... شكرا لك ... وبارك الله فيك

بس بدي تبسط لي الموضوع اكثر من هيك شوي ... انا بدي اعمل زر brows في windows form واختار ملف ثم اضغط رفع لهذا الملف، ، إلى مجلد في الموقع الخاص بي ، وعند الانتهاء فيعطيني رسالة انه تم تحميل الملف .

بالله إذا فيه مثال اوضح من هذا . لاني حاولت في web client بس ما مشي الحال معي .

#5

وينك يا سماقية

#6

السلام عليكم

اذا كان قصدك ان ترفع ملفات الى موقع ويب و لكن برنامج سطح المكتب فيوجد برامج جاهزة لهذا الامر

و مث لذلك برنامج رائع و اسمة Far Manager و هذا هو رابط له http://www.farmanager.com/download.php

استخدام Far Manager:

1- بعد أن تشغل البرنامج اضغط على Alt+F1

2- اذهب الى FTP

3- اضغط على shift+F4

4- ادخل معلومات الموقع المراد الاتصال به ثم أضغط على enter

و كذلك يوجد برنامج أخر و أسمة Total Commander

و الله في عون العبد ما دام العبد في عون أخيه

#7

اخي انا اسف على تأخير

شاهد هذا الرابط

http://www.itech4arab.com/forum/showthread...64645#post64645

-----------------------------------------------------------------------------------------------------------------------------





 

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

Mohammad Sonaiea
 

#8

ألف شكر يا اخواني .... جزاكم الله خيرا

هذا الموضوع مغلق.

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