⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadservice.asmx.cs

📁 This is not a very mean things
💻 CS
字号:
//-----------------------------------------------------------------------
//
// WebExpert.NET 1.0 
//
// (c) 2003, www.AspCool.com. All rights reserved.
// ASP酷技术网 版权所有
//
// 该源码下载自:http://www.51aspx.com
// 邮箱:tim@aspcool.com
//
// 版权声明:本程序仅供学习使用,你也可以修改后在网站上使用,但使用时必
// 须保留ASP酷技术网(www.AspCool.com)的版权信息和链接。本程序随《ASP.NET
// 网站建设专家》一书赠送,未经作者同意,不得随意修改、传播。
//
// 描述:
//   此文件包含下面的类:
//       UploadService
//
// 作者:     王保健
// 时间:     2005-01-15
//
//------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

using System.Configuration;
using System.IO;

namespace AspCool.WebExpert.Upload
{
	/// <summary>
	/// UploadService 是用来把文件保存到Service所在的服务器上。
	/// </summary>
	public class UploadService : System.Web.Services.WebService
	{
		public UploadService()
		{
			//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
			InitializeComponent();
		}

		#region 组件设计器生成的代码
		
		//Web 服务设计器所必需的
		private IContainer components = null;
				
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion


		[WebMethod]
		public void SaveFile(byte[] fileContent,string fileName)
		{
			// 要保存的文件你地址
			string fileAddress = ConfigurationSettings.AppSettings["strLocalPath"] + fileName;

			//定义一个文件流
			FileStream stream =  new FileStream(fileAddress,FileMode.Create, FileAccess.Write, FileShare.None);
			foreach (byte b in fileContent)
			{
				// 将一个字节b写入文件流的当前位置。
				stream.WriteByte(b);
			}
			
			// 关闭文件流
			stream.Close();			
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -