0
我目前正在嘗試使用visual studio 2012創建一個文件上傳web服務。但我的代碼返回「找不到路徑的一部分」 +我的路徑。asp.net文件上傳web服務 - 找不到路徑的一部分
我的路徑存在100%。
下面的代碼:
Web服務:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Data;
using System.Web.Services.Protocols;
using System.ComponentModel;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class OGcloud : System.Web.Services.WebService
{
public OGcloud() {}
[WebMethod]
public string UploadFile(byte[] f, string fileName)
{
try
{
MemoryStream ms = new MemoryStream(f);
FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath
("~/TransientStorage/") + fileName, FileMode.Create);
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs.Dispose();
return "OK";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
}
aspx.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Data;
public partial class User_MyParking : System.Web.UI.Page
{
public string msg = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["loct"] != null)
{
byte[] f = OGcloud_Upload.FileBytes;
OGcloud.OGcloudSoapClient access = new OGcloud.OGcloudSoapClient();
msg = access.UploadFile(f, OGcloud_Upload.FileName);
}
}
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
}
的ASPX形式:
<table class="Casual Center" dir="rtl" style="border-spacing:10px">
<tr>
<td colspan="2"><input type="text" name="loct" id="loct" style="width:300px"/></td>
</tr>
<tr>
<td colspan="2"><textarea id="info" name="info" draggable="false" style="width:950px; height:150px; resize:none;" class="Casual"></textarea></td>
</tr>
<tr>
<td colspan="2" id="Err_info"></td>
</tr>
<tr>
<td colspan="2" runat="server">
<asp:FileUpload ID="OGcloud_Upload" runat="server" />
</td>
</tr>
</table>
任何幫助將是非常讚賞。
你試過了嗎?Server.MapPath()' –
哪行代碼返回那個錯誤? –
謝謝你的回答!我試圖找到返回錯誤的行,發現fileupload給我「c:// fakepath/file」而不是實際的文件路徑。我在網上搜索,但無法找到一種方法來解決它,並得到實際的路徑... – omerg7