مرحبا
أنا عامل موقع وب وفيه المجلدات التالية Admin,Member,Image
الموقع هو بيع منتجات و يقوم الموقع باظهار صورة كل منتج
ضمن مجلد ال Admin عامل صفحة اضافة منتج تحتوي على detailsveiw مربوط ب Sqldatasource لادخال البيانات في جدول product ضمن ال database
ضمن ال detailsveiw حوات احد الحقول الى template و سويته Fileupload حيث من خلاله يستطع ال Admin استعراض الصور و اختيارصورة المنتج اللي عم بيدخله بحيث يتم حفظ الصورة
ضمن مجلد ال images و اسمها في الجدول product بحقل images
بس وقت التجريب عم يقلي انو مسار الصورة غير موجود
هذا هو الكود الخاص بال detailsveiw
Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting
'Access the fileupload2 in Template
Dim Fileupload2 As FileUpload = Me.DetailsView1.FindControl("FileUpload2")
If Not (Fileupload2.HasFile = False) Then 'Check to make sure we actually have a file to upload
Dim fileName As String = Fileupload2.FileName
Dim savepath As String
Dim strFileName As String
Dim strLongFilePath As String = Fileupload2.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1, StrReverse(strLongFilePath), "")
strFileName = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)
Select Case Fileupload2.PostedFile.ContentType 'Make sure the specified file is imagefile
Case "image/pjpeg", "image/jpeg", "image/bmp", "image/dib", "image/jpg", "image/jpe", "image/jfif", "image/tif", "image/tiff", "image/png", "image/gif" 'Make sure we are getting a valid JPG image
savepath = Server.MapPath("Images\product\" & fileName) 'Make sure file is not existed
If Dir(savepath) <> "" Then
If MsgBox("file already exist please change the name of image") Then
MsgBox("Operation has been cancelled") 'Cancel the Operation
e.Cancel = True
Exit Sub
End If
End If
Me.SqlDataSource1.InsertParameters("Logo").DefaultValue = Fileupload2.FileName.ToString ' set the Logo Paramete's value same as the fileupload2 filename
Fileupload2.PostedFile.SaveAs(Server.MapPath("Images\Product\" & fileName)) 'save to server
Case Else
'Not a valid jpeg image
MsgBox("The file you specified is Not a valid image")
e.Cancel = True
End Select
Else
'No thing specified
MsgBox("you did Not Specify anyimage ")
e.Cancel = True
End If
End Sub
End Class
بصراحة أنا لقيت حل للمشكلة بس ما عجبني الحل كان اني انشئ مجلد ال product ضمن مجلد images ضمن مجلدال Admin وغير المسار من Server.MapPath("Images\product\" & fileName) إلى Server.MapPath("Admin\Images\product\" & fileName)
لأانو الصور ماعاد بتظهر للزبون فقط للAdmin لأاني عامل Access rule على مجلد الadmin فقط لل admin group
أرجو من لديه الاجابة اسعافي بها
اني اسلم مشروع للجامعة و مضطر كتتييرررررررر