在方法之间传递参数值

编程入门 行业动态 更新时间:2024-10-17 22:26:38
本文介绍了在方法之间传递参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有ajaxfileupload控件,我想将图像插入数据库, 但我想插入它抛出按钮,而不是上传完成事件, 所以我按下按钮但是没有文件名属性! 任何帮助? ps我使用ajax控件因为我想先预览它并且它有一个预览图片的javascript代码 ____

protected 空隙 fileUploader_UploadComplete(对象发件人,AjaxFileUploadEventArgs文件) { // 用户可以将文件保存到文件系统,数据库或会话状态 if (file.ContentType.Contains( jpg )|| file.ContentType.Contains( gif) || file.ContentType.Contains( png)|| file.ContentType.Contains( jpeg)) { Session [ fileContentType _ + file.FileId] = file.ContentType; 会话[ fileContents _ + file.FileId] = file.GetContents(); } // 设置PostedUrl以预览上传的文件。 file.PostedUrl = string .Format( ?preview = 1& fileId = {0},file.FileId); }

protected void btnInsert_Click( object sender,EventArgs e) { // string filePath =〜/ _Manage_ / upimages /+ file。 FileName; // fileUploader.SaveAs(filePath); }

解决方案

我总是认为fileupload组件会让你将文件上传到非公开可访问的区域,比如例如_uploads / uploads文件夹和名称为upload243.doc的任何名称的文件,然后一旦上传(文件扩展名为PRESERVED),只有用户可通过按钮事件选择确定/取消。 如果用户确定那么你已经知道了文件名和位置,你可以根据自己的意愿将它分成数据库... 如果用户选择取消,那么你可以从中删除它你的服务器NON PUBLIC空间。 所以不要一次性考虑一次性完成动作,即使它有可能......试着把它想象成两步操作。 其中...... 1-用户选择文件而你上传到TEMPORARY位置 2a-用户选择确定然后你处理然后删除临时文件 或 2b-用户选择取消你删除临时文件文件

i have ajaxfileupload control , i want to insert the image to the database , but i want to insert it throw button , not from the upload complete event , so i make the button but there isn''t filename property ! any help ? p.s i use the ajax control because i want to preview it first and it have a javascript code that preview the image ____

protected void fileUploader_UploadComplete(object sender, AjaxFileUploadEventArgs file) { // User can save file to File System, database or in session state if (file.ContentType.Contains("jpg") || file.ContentType.Contains("gif") || file.ContentType.Contains("png") || file.ContentType.Contains("jpeg")) { Session["fileContentType_" + file.FileId] = file.ContentType; Session["fileContents_" + file.FileId] = file.GetContents(); } // Set PostedUrl to preview the uploaded file. file.PostedUrl = string.Format("?preview=1&fileId={0}", file.FileId); }

and

protected void btnInsert_Click(object sender, EventArgs e) { //string filePath = "~/_Manage_/upimages/" + file.FileName; //fileUploader.SaveAs(filePath); }

解决方案

I was always under the impression that the fileupload component alowed you to upload a file to a non publically accessible area like an _uploads/uploads folder for example and the file named to anything you wanted like upload243.doc and then once uploaded (and the file extension PRESERVED) and ONLY THEN the user is given the option to OK/Cancel via your button event. And if the user OK then you already know the file name and location and you can chunk it into your DB as you like... And if the user choose CANCEL then you can delete it from your servers NON PUBLIC space. So dont neccessarily think about completing the action in one shot, even though it may be possible.... try to think of it as a two step manouvre. where... 1- User chooses file and you UPLOAD to TEMPORARY location 2a- User choose OK and you process and then delete the temporary file OR 2b- User choose CANCEL you delete the temporary file

更多推荐

在方法之间传递参数值

本文发布于:2023-11-15 10:19:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!