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

📄 upload.asmx.cs

📁 CS导航Logo ,在Logo上显示Loading
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.Services;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Dime;

namespace BufferedUpload.Upload {

	[WebService(Namespace="http://yourdomain.com/upload/")]
	public class Upload : System.Web.Services.WebService 
	{
		/// <summary>
		/// This method initializes a buffered upload. It creates a temporary file on the
		/// server's temp directory and a session object that references the temp file. It returns
		/// a string value representing the InstanceId of the buffered upload. This id should be 
		/// passed to the proceding calls to AppendChunk(), Save(), and Close() methods.
		/// </summary>
		[WebMethod(EnableSession=true)]
		public string Initialize(string Filename, bool Overwrite) 
		{
			return new Instance(Filename, Overwrite).Initialize().Id; 
		}

		/// <summary>
		/// This method appends a dime attachment to an upload in progress. 
		/// </summary>
		/// <param name="InstanceId">The string returned by Initialize() method.</param>
		/// <param name="offset">The offset at which to start writing.</param>
		/// <param name="length">The size of the buffer.</param>		
		[WebMethod(EnableSession=true)]
		public void AppendChunk(string InstanceId, long offset, int bufferSize) 
		{
			Instance i = Instance.GetInstanceById(InstanceId);
			if (i != null) 
			{
				if(RequestSoapContext.Current == null || RequestSoapContext.Current.Attachments.Count == 0)
					throw new SoapFormatException("No SOAP attachments included in message");
				Stream dimeStream = RequestSoapContext.Current.Attachments[0].Stream;
				byte[] buffer = new byte[dimeStream.Length];
				dimeStream.Read(buffer, 0, buffer.Length);
				dimeStream.Close();								
				i.AppendChunk(buffer, offset, bufferSize);
			}
			else
				Instance.CustomSoapException("Instance Not Found", InstanceId);		
		}

		/// <summary>
		/// This method removes the upload instance from session state .
		/// </summary>
		/// <param name="InstanceId">The string returned by Initialize() method.</param>
		[WebMethod(EnableSession=true)]
		public void RemoveInstance(string InstanceId)
		{
			Instance i = Instance.GetInstanceById(InstanceId);
			if(i != null)
				i.RemoveFromSession();	
			// else: nothing to remove anyway, so don't report any errors.
		}
	}
}

⌨️ 快捷键说明

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