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

اداة رفع الملفات ؟

مغلق
بدأه ice4ever في 29 يناير 2007 · 1 رد · 501 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم يا اخواني واخواتي

الان بأستعمل اداة رفع الملفات Upload file وهي شغالة معايا تمام

بس كيف اقوم بتحديد المكان الي اريد انه الملف ينزل فيه على الموقع ؟

ممكن تساعدوني . انا الان بأرفعه بس بينزل في المجلد الرئيسي . يعني انا مثلا اريد ارفعه لمجلد الصور ميف احددله ؟

مشكور

#2

حدد المجلد أو المسا ر مثال:

  Dim FilePath As String = Server.MapPath("Documents\")

وبعدين أرفع الملف :

 

myFile.PostedFile.SaveAs(FilePath & FName)

وهذا كود كامل لرفع ملف :

						 Try 'Using a Try - catch prosedure to handle unhandled exceptions.
			If Not (myFile.PostedFile Is Nothing) Then
				Dim intFileNameLength As Integer
				Dim strFileNamePath As String
				Dim strFileNameOnly As String
				Dim Test As String

				'Be sure to add a folder called "Documents" 
				'in the same directory as your application.

				'The Server.MapPath("Documents\") is telling 
				'to upload the files to a folder called
				'Documents in the same path as the application.
				Dim FilePath As String = Server.MapPath("Documents\")

				'Logic to find the File Name (excluding the path)
				strFileNamePath = myFile.PostedFile.FileName
				intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")
				strFileNameOnly = Mid(strFileNamePath, _
						 (Len(strFileNamePath) - intFileNameLength) + 2)

				'Logic to find the extension. I have choosen 
				'to only upload pdf's doc's and xls's.
				'If you don't use any limitation, take it away.

				Test = Right(strFileNameOnly, strFileNameOnly.Length - strFileNameOnly.IndexOf(".") - 1)
				FName = FName & "." & Test
				FType = FileType(Test)

				If Not FType = "" Then

					'In my prosject I will limit the size 
					'on the file to 0,5Mbit.
					If CStr(myFile.PostedFile.ContentLength) < 500000 Then
						'Make the message labels visible

						myFile.PostedFile.SaveAs(FilePath & FName)
					Else
						  lblFileSize.Text = "حجم الملف: " _
						& CStr(myFile.PostedFile.ContentLength) & " bytes"
						  lblFileSize.Text = "حجم الملف أكبر من امسموح به"
						'A message to the client.
					End If
					Else
						lblMsg.Text = "This was not a pdf, " & _
						   "doc or xls file."  'A message to the client.
					Return True
				Else
					lblMsg.Text = " امتداد الملف المرفق غير مسموح به"
				End If
			Else
				lblMsg.Text = "يجب اختيار الملف "
				Return False
			End If
		Catch ex As Exception
			Return False
		End Try

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

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