- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,这里是代码,然后我将解释我的问题:-
Protected Sub btnupload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
If (IsPostBack) Then
HandleUploadedFile()
Dim savePath As String = "Images\"
If (fileUpload.HasFile) Then
Dim fileName As String = fileUpload.FileName
savePath = Server.MapPath(savePath) + fileName
fileUpload.SaveAs(savePath)
Me.Label1.Text = "Your file was saved as " & fileName
adp.Insert(fileUpload.FileName)
Else
Me.Label1.Text = "You did not specify a file to upload."
End If
End If
End Sub
每次我跟踪代码时,它都会说 (fileUpload.HasFile)=false
之后再也看不到代码,然后跳转到 else 语句,这就是代码的其余部分
Private Sub HandleUploadedFile()
' get the root of the web site
Dim root As String = Server.MapPath("~/")
' clean up the path
If Not root.EndsWith("\") Then
root += "\"
End If
' make a folder to store the images in
Dim fileDirectory As String = root & "Images/"
' create the folder if it does not exist
If Not System.IO.Directory.Exists(fileDirectory) Then
System.IO.Directory.CreateDirectory(fileDirectory)
End If
' make a link to the new file
Dim link As String = "<a href='Images/{0}' target='_blank'>{1}</a>{2}{3}"
' loop through the file in the request
For i As Integer = 0 To Request.Files.Count - 1
' get the file instance
Dim fi As HttpPostedFile = Request.Files.[Get](i)
' create a byte array to store the file bytes
Dim fileBytes As Byte() = New Byte(fi.ContentLength - 1) {}
' fill the byte array
Using stream As System.IO.Stream = fi.InputStream
stream.Read(fileBytes, 0, fi.ContentLength)
End Using
' create a random file name
Dim fileName As String = Guid.NewGuid().ToString()
'write the original file to the file system
File.WriteAllBytes(fileDirectory + fileName & ".jpg", fileBytes)
litText.Text += String.Format(link, fileName & ".jpg", fileName & " Original", "<br/>", "")
' write the resized file to the file system
File.WriteAllBytes(fileDirectory + fileName & "_small.jpg", ResizeImageFile(fileBytes, 100))
litText.Text += String.Format(link, fileName & "_small.jpg", fileName & " Small", "<br/>", "<br/>")
' cleanup
litText.Visible = True
fileBytes = Nothing
Next
End Sub
Private Shared Function ResizeImageFile(ByVal imageFile As Byte(), ByVal targetSize As Integer) As Byte()
Using oldImage As System.Drawing.Image = System.Drawing.Image.FromStream(New MemoryStream(imageFile))
Dim newSize As Size = CalculateDimensions(oldImage.Size, targetSize)
Using newImage As New Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb)
Using canvas As Graphics = Graphics.FromImage(newImage)
canvas.SmoothingMode = SmoothingMode.AntiAlias
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality
canvas.DrawImage(oldImage, New Rectangle(New Point(0, 0), newSize))
Dim m As New MemoryStream()
newImage.Save(m, ImageFormat.Jpeg)
Return m.GetBuffer()
End Using
End Using
End Using
End Function
Private Shared Function CalculateDimensions(ByVal oldSize As Size, ByVal targetSize As Integer) As Size
Dim newSize As New Size()
If oldSize.Height > oldSize.Width Then
newSize.Width = CInt((oldSize.Width * (CSng(targetSize) / CSng(oldSize.Height))))
newSize.Height = targetSize
Else
newSize.Width = targetSize
newSize.Height = CInt((oldSize.Height * (CSng(targetSize) / CSng(oldSize.Width))))
End If
Return newSize
End Function
End Class
最佳答案
检查您是否正在使用 UpdatePanel,如果是,则在 Page.Init 中执行以下操作:
protected void userView_Init(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl(uploadFileButton);
}
关于asp.net - 如果 (fileUpload.HasFile)=false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/765683/
我正在配置 blueimp 以在单击发布按钮时上传图像。我的问题是它没有调用 $('#fileupload').fileupload 函数。我已经包含了以下 javascript 文件。以下是我的代码
我正在使用 Firebase 构建一个 Angular 应用程序,以将图像上传到数据库并从那里检索它。 上传文件.service.ts import {Injectable} from '@angul
我应该使用哪个库?唯一的目的是上传文件。在处理大型请求时,我想在性能和可扩展性方面使用最佳库。如果我的项目扩大规模,我最终将使用 CDN 服务。 最佳答案 以下是在这种情况下选择图书馆时必须考虑的一些
我尝试什么:我想使用 jQuery mobile 在 JSF 页面中上传带有 Primefaces FileUpload 标记的图片。此面仅在桌面浏览器上可用,但也应具有与其他页面一样的外观。问题:总
我在 gridview 中使用了 Ajax fileupload 控件,为 gridview 中的每条记录上传文件。我使用了 ajax fileupload 控件,因为我也需要拖放上传功能。它的工作很
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章FileUpload 控件禁止手动输入的方法由作者收集整理,如果你对这篇
我正在使用 primefaces fileUpload 组件,然后我检查了 FileUploadEvent.getFile 但我没有看到可靠地获取扩展名的方法。有任何想法吗? 最佳答案 getFile
在我的 GWT 项目中,我想: 为 FileUpload 小部件设置过滤器,使其只接受 JPG 文件。 启用 myButton如果 FileUpload 小部件,称为 chooser , 选择了任何文
我的 Extjs 应用程序中有一个文件上传字段。我尝试通过以下代码将文件加载到服务器: var form = Ext.getCmp('ProcImpNewSugFileForm').getForm()
长话短说,我想允许用户将文件上传到服务器。我尝试使用 Jquery 文件上传功能,但它似乎无法正常工作。 我已经简化了我的代码以查明错误/错误。我认为完成的例程没有被调用。 因此只有第一个 conso
我正在上传一个带有 PF 3.5 File Uploader 的文件 我的上传方法如下所示: public void handleFileUpload(FileUploadEvent event) {
我正在使用 FileUpload 控件上传图片,我可以使用那个浏览按钮选择图片,但是当我尝试预览所选图片时,我没有得到文件名,它显示为空.. protected void btnImgUpload_C
如何仅使用 FileUpload 代码隐藏进行上传?我的控件是代码隐藏的,因为我有 Dropdown_SelectedIndexChanged 并且需要生成各种数量的控件。我可以很好地列出控件并将文件
出于某种原因,当我尝试上传多个文件时,所有文件都成为第一个文件的副本。当我说副本时,我指的是不同的文件名、不同的文件扩展名,但所有图像中的图片相同。 例子: 我选择了四个文件。 2个png,2个jpg
我正在做一个简单的测试,只是尝试上传一个文件,将其转换为无符号 8 数组,然后将其记录到控制台 我的代码运行完美,但每次我按下按钮上传文件时,控制台都会递增地重复输出,让我解释一下: 第一次点击控制台
我正在使用 apache 的 FileUpload 将一些文件上传到我的网络服务器。问题是我不想将它们上传到机器上的特定位置,即:c:\tmp,而是上传到相对路径,例如 /ProjectName/tm
我想在我的 .FileUpload button 上应用这个 css,但它只适用于 IE 而不是 Chrome,我仍然不知道它有什么问题。有人有想法吗? 感谢帮助 .FileUpload { wid
我正在使用 asp.net C# FIleUpload。我遇到了一个问题,那就是当我上传图片并将其存储在指定的文件夹中时,刷新页面后图片会再次上传,次数与刷新页面的次数一样多。我尝试启用和禁用 Vie
我想知道为什么我的方法FileUpload.HasFile总是为null .. 这是我使用的Xaml。
我的 Web 表单上有一个 FileUpload 控件 (FileUpload1),还有一个“Sumbit”按钮、一个标签和一个包含 UserID 的隐藏字段。我在按钮的点击事件中有以下代码: str
我是一名优秀的程序员,十分优秀!