解决方案 »
- 关于Session的bug,.Net2.0是否还存在,有没有好的解决方案
- 除了IIS,还有什么服务器可以运行ASP.NET
- [浏览器兼容]按钮点击后播放提示声音
- 字符串组合的问题
- 一个奇怪的问题,请高手指教
- 在DataGrid中删除一条记录给于提示
- 提示退出session的问题
- 如何实现服务器断控件事件在客户端运行
- MS SQL text格式能够保存多少文本呢?
- 我的程序里面 left 这个函数怎么不能用,提示说 left 是一个类型,不能用作表达式
- 不能在具有唯一索引 'admin_name' 的对象 'dbo.admins' 中插入重复键的行
- 在SQL Server2005里怎么把函数绑定到一个字段上!
参考
http://group.gimoo.net/review/156483
txtImgUrl,这个框里面填写的是图片url的地址``
对了,就是比如百度上的图片那个链接可以直接拿来做上传用么?
这些我不懂,再问下,假如我现在访问一个网站,我上传自己的头像的时候``
那我的头像图片提交到该网站的服务器的时候``
地址是怎么样的?
这样也行?
还是出问题` `
上传出错System.Net.WebException: 未能找到路径“C:\Documents and Settings\Administrator\桌面\sadan\未命名.jpg”的一部分。 ---> System.Net.WebException: 未能找到路径“C:\Documents and Settings\Administrator\桌面\sadan\未命名.jpg”的一部分。 ---> System.IO.DirectoryNotFoundException: 未能找到路径“C:\Documents and Settings\Administrator\桌面\sadan\未命名.jpg”的一部分。 在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) 在 System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async) 在 System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint) --- 内部异常堆栈跟踪的结尾 --- 在 System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint) 在 System.Net.FileWebRequest.GetResponseCallback(Object state) --- 内部异常堆栈跟踪的结尾 --- 在 System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.FileWebRequest.GetResponse() 在 UI.Admin.SystemInfo.SysInitPage.downRemoteImg(String imgpath) 位置 C:\Documents and Settings\Administrator\桌面\明凯系统\Mikia\UI\Admin\SystemInfo\SysInitPage.aspx.cs:行号 81
System.Net.FileWebRequest.GetResponse()
还是这个函数出问题``
= =``
是这样的?
那我现在想实现这样一个功能,就是说我现在不想用.net提供的上传组件上传图片` `
我想点击一个按钮,然后弹出一个选择文件的东西,
这点已经实现了,就是我用JS激发一个upload控件的点击事件``
选择一个文件,然后选择之后就弹出一个层来显示我选择的图片``
可是问题是,当我点击提交按钮之后,后台的上传控件就找不到我刚选择的文件信息``
然后我就用一个文本框来装我选择的文件URL``
现在就是想把这个URL的图片保存到我本地文件夹中` `
这样的功能该怎么实现?
{
String savePath = @"E:\3\MyOffice\images\Users\";
string extension = System.IO.Path.GetExtension(fileUpImg.FileName);
if ((extension == ".jpg") | (extension == ".gif"))
{
savePath += userInfo.UserId + ".jpg";
fileUpImg.SaveAs(savePath);
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('只允许上载扩展名为 .jpg 或 .gif 的图片')</script>");
return;
}
}这是以前存本地路径的时候用的,用的是fileupload
现在就是upload控件里面选择的文件信息获取不到``
fileUpImg.FileName根本就是空的``= =``
也就是fileupload里的fileUpImg.FileName
大哥``
现在的问题我想您还是没有搞清楚` `
要上传的话至少得有个源文件吧``
目前只有路径` `
而upload控件里并没有任何源文件的信息``
您上面的方法就相当于在硬盘里面写入一个XXXX.JPG的文件``
但是文件里面什么都没有的``
直接用upload提供的saveas方法我早就试过了``
没用` `
写入的文件里面什么都没有``
字节0的文件``
{
var imgs = document.getElementById("displayImg");
imgs.style.display="block";
imgs.style.top = "80px";
imgs.style.left = "490px";
document.getElementById("txtImgUrl").value = document.getElementById("fulImage").value;
document.getElementById("Image1").src = document.getElementById("fulImage").value;
}<td class="td">后台LOGO地址:</td>
<td>
<asp:FileUpload ID="fulImage" runat="server" style="width:150px; display:none;" />
<asp:TextBox runat="server" ID="txtImgUrl" style="display:none; width:500px;" ></asp:TextBox>
<input type="button" id="aaa" onclick="openUpLoad()" class="buttonStyle" style=" width:150px;" value="点击上传图片" />
</td>
<td style="border-right:1px solid #cccccc;" class="textStyle">
<div id="displayImg" ondblclick="this.style.display='none'" style="position:absolute; display:none;">
<img id="Image1" width="120px" height="120px" />
</div>
网站logo地址
</td>这是我页面的代码以及相应的JS```
点击那个显示的按钮之后,到后台就找不到上传的控件信息了``
里面是空的,字节数也是0```
document.getElementById("fulImage").click();
lookupImg();
}
而不是图片上传程序.如果你在本地使用是可以,因为你有权限.如果你上传到服务器上,却给URL一个物理地址,如 c:\abc\xx.jpg这是不允许的,因为你无权读取服务器上这个目录的文件.
这个上传控件找不到信息跟防火墙也有关系的么``
对了``
还有一个现象``
就是这个上传控件如果我用客户端控件的话,就是<input type='file' />
这个点提交的时候就可以直接到后台``
但是如果我用上面这个服务端控件的话``
第一次点击提交按钮会先清空上传控件里的信息``
然后再点一次才可能进后台``
这是什么情况` `<asp:Button runat="server" ID="btnSubmit" Text="提交" CssClass="buttonStyle"
onclick="btnSubmit_Click" />
这是提交按钮,我什么东西都没搞额``= =``
这个有关系不?那个fileupload区不到值
放在层里面试一试
本地服务器,
现在就是有一个很奇怪的现象``
就是说我选择过文件之后,上传控件的那个文本域里也已经有值了``
但是我点提交按钮的时候第一次肯定提交不了,点了之后会清空上传的控件``
然后再点第二次的时候才会提交到后台``
我尝试着用JS去提交``
但是dopostback函数里面,老是报__EVENTTARGET空值针异常``
而且还不知道能不能提交``
这是怎么回事额``
是不是上传控件的值是只读的``
所以提交之前得清空掉才能提交``?
不对啊``
控件里的值也不是我代码给的``
是选择的额``
我郁闷了` `
这就奇怪了.放出
html页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SysInitPage.aspx.cs" Inherits="UI.Admin.SystemInfo.SysInitPage" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.td
{
font-size: 14px;
color: #5cacee;
text-align: right;
}
.input
{
margin-left: 25px;
width: 150px;
}
input
{
border: 1px solid #cccccc;
}
.textStyle
{
font-size: 13px;
color: #5cacee;
}
td
{
border-left: 1px solid #cccccc;
border-top: 1px solid #cccccc;
}
.buttonStyle
{
background-color: #ffffff;
border: 1px solid #000000;
width: 50px;
height: 20px;
}
</style> <script language="javascript">
//显示图片层,并把地址赋值给文本框
function lookupImg() {
var imgs = document.getElementById("displayImg");
imgs.style.display = "block";
imgs.style.top = "80px";
imgs.style.left = "490px";
document.getElementById("txtImgUrl").value = document.getElementById("fulImage").value;
document.getElementById("Image1").src = document.getElementById("fulImage").value;
} function openProDiv(items1, items2) {
var items = document.getElementById(items1);
if (items.style.display == "none") {
items.style.display = "block";
items2.style.borderBottom = "0px solid #ddeeff";
items.style.borderTop = "0px solid #ddeeff";
items2.style.backgroundColor = "#ddeeff";
} else {
items2.style.borderBottom = "1px solid #cccccc";
items.style.borderTop = "1px solid #cccccc";
items.style.display = "none"
items2.style.backgroundColor = "#ffffff";
}
}
function giveTextValue(item1, item2, items3) {
item2.value = items3.innerText;
openProDiv(item1, item2);
} //激活上传控件
function openUpLoad() {
document.getElementById("fulImage").click();
lookupImg();
} function postForm() {
__doPostBack("btnSubmit", "");
} function __doPostBack(eventTarget, eventArgument) {
var theForm = document.forms[0];
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
</script></head>
<body>
<form id="form1" runat="server">
<div>
<div style="height: 40px; background-color: #D3FAE3; font-size: 17px; color: #3399FF">
<strong>系统初始化设置</strong>
<br />
<span style="border-bottom: 1px solid #cccccc; margin-left: 120px;">
<!--提交按钮-->
<asp:Button runat="server" ID="btnSubmit" Text="提交" CssClass="buttonStyle" OnClick="btnSubmit_Click" />
<asp:Button runat="server" ID="btnReturn" Text="返回" CssClass="buttonStyle" />
</span>
</div>
<table width="100%" border="0" style="font-size: 14px; margin-top: 10px;" cellspacing="0"
cellpadding="6">
<tr>
<td class="td">
后台LOGO地址:
</td>
<td>
<!--上传控件-->
<asp:FileUpload ID="fulImage" runat="server" Style="width: 150px; display: block;" />
<!--存放地址文本框-->
<asp:TextBox runat="server" ID="txtImgUrl" Style="display: none; width: 500px;"></asp:TextBox>
<!--激活上传控件按钮-->
<input type="button" id="aaa" onclick="openUpLoad()" class="buttonStyle" style="width: 150px;"
value="点击上传图片" />
</td>
<td style="border-right: 1px solid #cccccc;" class="textStyle">
<!--显示图片的层-->
<div id="displayImg" ondblclick="this.style.display='none'" style="position: absolute;
display: none;">
<!--图片-->
<img id="Image1" width="120px" height="120px" />
</div>
网站logo地址
</td>
</tr>
<tr>
<td class="td">
是否关闭网站:
</td>
<td class="textStyle">
<asp:RadioButton Checked="true" GroupName="isCLoseWeb" Style="width: 30px; margin-left: 25px;"
ID="rdoYes" runat="server" Text="是" />
<asp:RadioButton ID="rdoNo" GroupName="isCLoseWeb" Style="width: 30px;" runat="server"
Text="否" />
</td>
<td style="border-right: 1px solid #cccccc;" class="textStyle">
选择是否关闭网站
</td>
</tr>
<tr>
<td class="td">
关闭网站描述:
</td>
<td>
<asp:TextBox runat="server" ID="txtCloseWebDesc" TextMode="MultiLine" />
</td>
<td style="border-right: 1px solid #cccccc;" class="textStyle">
填写关闭网站后其他人访问该站时的提示信息
</td>
</tr>
<tr>
<td class="td">
版权信息:
</td>
<td>
<asp:TextBox runat="server" ID="txtCopyRight" />
</td>
<td style="border-right: 1px solid #cccccc;" class="textStyle">
网站尾部出现的版权信息
</td>
</tr>
<tr>
<td width="18%" class="td">
商品所属分类:
</td>
<td width="33%" style="height: 25px;">
<asp:TextBox runat="server" ID="txtProTpId" ReadOnly="true" onclick="openProDiv('protypeDiv',this)" />
<div id="protypeDiv" runat="server" style="position: absolute; display: none; left: 241px;
top: 245px; color: #5cacee; width: 148px; background-color: #ddeeff; border: 1px solid #cccccc;"
ondblclick="openProDiv('protypeDiv',document.getElementById('txtProTpId'))">
</div>
</td>
<td style="border-right: 1px solid #cccccc;" width="49%" class="textStyle">
选择分类中代表商品的分类节点
</td>
</tr>
<tr>
<td style="border-bottom: 1px solid #cccccc;" class="td">
新闻所属分类:
</td>
<td style="border-bottom: 1px solid #cccccc; height: 25px;">
<asp:TextBox runat="server" ID="txtNewsTpId" ReadOnly="true" onclick="openProDiv('newTypeDiv',this)" />
<div id="newTypeDiv" runat="server" style="position: absolute; display: none; left: 241px;
top: 282px; color: #5cacee; width: 148px; background-color: #ddeeff; border: 1px solid #cccccc;"
ondblclick="openProDiv('newTypeDiv',document.getElementById('txtNewsTpId'))">
</div>
</td>
<td style="border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc;" class="textStyle">
选择分类中代表新闻的分类节点
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
这就是我整个页面的html代码,没有加注释的都是跟这个无关的,你看下吧,
我也搞不清楚怎么回事,把上传控件显示出来就能看到效果了,
第一次点提交按钮它首先就是清空上传控件里的值的``