Upload er billeder virker i Visual Studio men ikke på server ?
Hey boy's and girl's :PHar lavet en funktion til at uploade billeder og derefter komprimere dem, som virker når jeg køre den igennem Visual Studio uden problemer. Men når jeg så køre den fra serveren(Curanet) får jeg fejlen
fejl_1, som jeg har sat den til at retunere hvis "If File.Exists(fileUpload1.FileName) Then" ikke går igennem.
Hvis jeg så fjerner denne if sætning får jeg denne fejl ved upload af billede
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: qwe.jpg
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[FileNotFoundException: qwe.jpg]
System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) +379411
System.Drawing.Image.FromFile(String filename) +6
UploadThumb.UploadFil(HttpPostedFile fileUpload1, String OutputPath) +292
Admin_DMMD.btnUpload_Click(Object sender, EventArgs e) +509
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
---------------------------------
String jeg sender til min funktion:
objUploadImg.UploadFil(fulFileKategori.PostedFile, Server.MapPath("Images\"))
---------------------------------
Public Class UploadThumb
Function UploadFil(ByVal fileUpload1 As System.Web.HttpPostedFile, ByVal OutputPath As String) As String
OutputPath = OutputPath & "Thumbs\"
If Not (fileUpload1 Is Nothing) Then
If File.Exists(fileUpload1.FileName) Then
Dim filename As String = Path.GetFileNameWithoutExtension(fileUpload1.FileName)
Dim counter As Integer = 0
Dim strFileName As String = String.Empty
While (True)
counter += 1
strFileName = filename & "_" & counter.ToString() + Path.GetExtension(fileUpload1.FileName)
strFileName = Replace(strFileName, "-", "_")
strFileName = Replace(strFileName, " ", "_")
strFileName = Replace(strFileName, "æ", "ae")
strFileName = Replace(strFileName, "ø", "oe")
strFileName = Replace(strFileName, "å", "aa")
If File.Exists(OutputPath & "ThumbMedium_" & strFileName) = False Then
Exit While
End If
End While
Dim bm As Bitmap = System.Drawing.Image.FromFile(fileUpload1.FileName)
Dim newWidth As Integer = (85 / bm.Height) * bm.Width
Dim resized As Bitmap = New Bitmap(newWidth, 85)
Dim g As Graphics = Graphics.FromImage(resized)
g.InterpolationMode = InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = PixelOffsetMode.HighQuality
g.CompositingQuality = CompositingQuality.HighQuality
g.DrawImage(bm, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)
Dim StrNewFilePath As String = OutputPath
g.Dispose()
Dim newFilename As String = StrNewFilePath & strFileName 'For the Database'
Dim newStrFileName As String = StrNewFilePath & "ThumbMedium_" & strFileName
resized.Save(newStrFileName, ImageFormat.Jpeg)
Return strFileName
End If
End If
Return "Fejl_2"
End Function
---------------------------------------
Mange tak :D super forum!