asp.net实现创建映射,发送文件,删除映射
来源:互联网 发布:中通淘宝合作价格表 编辑:程序博客网 时间:2024/06/05 11:19
前台页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<INPUT class="inputnormal" id="txtDown" style="WIDTH: 400px; HEIGHT: 24px" type="file"
size="47" name="smlPic" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
后台文件:
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;
using System.IO;
using System.Diagnostics;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
try
{
p.Start();
p.StandardInput.WriteLine("net use h: ////IP//共享文件夹名称/"密码/" /user:用户名");//创建映射
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();
string shortSmlPicFileName = "";
string smlPicFileName = "";
if (txtDown.PostedFile.FileName.Trim() != "")
{
shortSmlPicFileName = GetUniqueFileName(txtDown.PostedFile.FileName);
smlPicFileName = "h:/" + shortSmlPicFileName;
UpLoadPic(txtDown, smlPicFileName);
}
string vSmlPicFileName = (shortSmlPicFileName == "") ? "" : "h:/" + shortSmlPicFileName;
}
catch (Exception ex)
{
}
finally
{
p.Start();
p.StandardInput.WriteLine("net use h: /del");//删除映射
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();
}
}
private string GetUniqueFileName(string fileName)
{
string newFileName = Guid.NewGuid().ToString();
string ExtName = Path.GetExtension(fileName);
return newFileName + ExtName;
}
private void UpLoadPic(HtmlInputFile inputFile, string fileName)
{
if (inputFile.PostedFile != null)
{
inputFile.PostedFile.SaveAs(fileName);
}
}
}
注意:共享文件夹要有写的权限
- asp.net实现创建映射,发送文件,删除映射
- asp.net实现创建映射,发送文件,删除映射
- ASP.NET 2.0如何实现URL映射
- ASP.NET实现URL映射的方法
- ASP.NET URL 映射
- 利用文件映射发送文件
- asp.net c#实现文件的创建、移动、删除、复制
- 创建内存映射文件
- linux 创建文件映射
- 给ASP.NET项目添加less文件MIME映射
- ASP.NET 2.0 URL映射
- ASP.NET 的URL映射
- ASP.NET 2.0的URL映射的实现方法
- ASP.NET 2.0的URL映射的实现方法
- ASP.NET 2.0的URL映射的实现方法
- 学习《ASP.NET 2.0的URL映射的实现方法》
- ASP.NET 2.0的URL映射实现方法
- UrlRewritingNet 完美实现 ASP.NET 2.0 中的URL重写(映射)
- 盖茨:软件开发不只是坐在办公室里猛写代码
- 专家看台:纯做技术是自娱自乐 抛开技术做技术才是出路
- Symbian S60开发,在SettingList中使用RadioButton的问题及解决方法。
- bosi設置01
- 人生经验
- asp.net实现创建映射,发送文件,删除映射
- GB2312与UTF-8
- bosi設置02
- Introduction of SUN SPOT (transshipment from http://www.sunspotworld.com/about/index.php)
- asp.net树
- 操作Execl
- 动态调用WebService,首先声明:这篇文章是我从网上学习来的,根据自己实际的情况写的,只给自己看的!
- 在数据库中 如何进行分类分组并总计SQL信息(转载)
- 使用CUBE和ROLLUP对数据进行汇总(转载)