| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 940 人关注过本帖, 1 人收藏
标题:程序问题,求助
只看楼主 加入收藏
zore0
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2008-9-8
收藏(1)
 问题点数:0 回复次数:3 
程序问题,求助
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _5_08 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Image1.Visible = false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strDir = FileUpload1.PostedFile.FileName;
        int myPos = strDir.LastIndexOf("\\");
        string strName = strDir.Substring(myPos);
        string strType = strName.Substring(strName.LastIndexOf(".") + 1);
        string strPath = Server.MapPath(".") + strName;
        if (strType == "jpg" || strType == "gif" || strType = "bmp" || strType = " png")
        {
            FileUpload1.SaveAs(strPath);
            Image1.ImageUrl = strName;
            Image1.Visible = true;
            Response.Write("图片上传成功");
        }
    }
}


 运算符“||”无法应用于“bool”和“string”类型的操作数,怎么解决?

 LastIndexOf("\\")和Substring()是什么意思?
希望大家帮我一下,谢谢各位了。




上面的问题解决了又出现这样的问题:在这句string strName = strDir.Substring (myPos);出现
System.ArgumentOutOfRangeException: StartIndex 不能小于 0。 怎么办?

[[it] 本帖最后由 zore0 于 2008-9-22 13:27 编辑 [/it]]
搜索更多相关主题的帖子: void public false 
2008-09-22 10:51
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
LastIndexOf("\\")  用来截取最后的\\后面的内容
Substring()  截取指定位置的字符串
你写的我感觉有点糊涂
用下面的那个方法试试

string photoname1 = FileUpload1.PostedFile.FileName;
取得路径
string photopath = Path.GetExtension(photoname1).ToString();
取得扩展名

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-09-22 10:59
初学Delphi
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:330
专家分:0
注 册:2006-4-4
收藏
得分:0 
strType = "bmp" || strType = " png")
这里  判断相等写错了
2008-09-22 11:50
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
strType = "bmp" || strType = " png"
改成:
strType == "bmp" || strType == " png
2008-09-22 11:54
快速回复:程序问题,求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017352 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved