今天在朋友介绍了份兼职的工作,老板(新加坡)出了道在线的改错测试题:
http://oa.ueeeu.com/WebApplication2/WebForm1.aspx(这是我后来放上去的测试代码,和原代码功能差不多)
上传文件老是找不到d盘,我的代码如下:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;namespace WebApplication2
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlInputFile File1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} private void creaml()
{
Random TempNameInt    = new Random(); 
string NewDocDirName  = TempNameInt.Next(100000000).ToString();
HtmlForm FrmCompose   = (HtmlForm)this.Page.FindControl("DeliverDocument");
string FileName       = "";
//Directory.CreateDirectory("E:\\temp");
//Response.Write(Server.MapPath("~\\WebApplication2\\AttachFiles\\tmp"));
//Response.End();
if(Directory.Exists(Server.MapPath(".")+"\\AttachFiles\\tmp"))
{
Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles\\tmp\\"+NewDocDirName+"asfsaf"); for (int i=0;i<FrmCompose.Controls.Count;i++)
{
if(FrmCompose.Controls [i].GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputFile")
{

HtmlInputFile hif = ((HtmlInputFile)(FrmCompose.Controls[i]));
if(hif.PostedFile.FileName.Trim()!="")
{
FileName = System.IO.Path.GetFileName(hif.PostedFile.FileName);
hif.PostedFile.SaveAs(Server.MapPath(".")+"\\AttachFiles\\tmp\\"+NewDocDirName+"asfsaf\\"+FileName);

}
hif=null;
}
}
}
else
{
Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles\\tmp");
creaml();
}

}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
creaml();
}
}
}
aspx部分:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm14</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="DeliverDocument" method="post" encType="multipart/form-data" runat="server">
<FONT face="宋体">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 424px; POSITION: absolute; TOP: 192px" runat="server"
Text="Button"></asp:Button></FONT> <INPUT id="File1" type="file" name="File1" runat="server" class="inputcss" style="Z-INDEX: 102; LEFT: 152px; POSITION: absolute; TOP: 192px">
</form>
</body>
</HTML>
上面的代码执行
Directory.CreateDirectory("E:\\temp");完全不会报错
Directory.CreateDirectory("d:\\temp");就说找不到d:\盘(d盘是肯定有的)
这很明显是d盘没有权限吗,可以老板让人把user和iis,asp.net的权限都给了还是不行.请各位高手分析理除了权限以外还有什么其它原因(另外听说在其它的机器上程序没问题)

解决方案 »

  1.   

    hif.PostedFile.SaveAs(Server.MapPath(".")+"\\AttachFiles\\tmp\\"+NewDocDirName+"asfsaf\\"+FileName);
    改成
    hif.PostedFile.SaveAs(HttpContext.Current.Request.MapPath("/")+"\\AttachFiles\\tmp\\"+NewDocDirName+"asfsaf\\"+FileName);
      

  2.   

    在线的改错测试题????
    --------------------------
    呵呵~~~,冷笑话~~~你先告诉我,那个服务器是是2000server还是2003??
      

  3.   

    D盘是什么分区?有可能是FAT32的吧。
    如果是NTFS的,给来宾帐号的权限了吗?
      

  4.   

    FAT32 需单设可写共享.
    NTFS 就不必.