• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UploadedFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UploadedFile的典型用法代码示例。如果您正苦于以下问题:C# UploadedFile类的具体用法?C# UploadedFile怎么用?C# UploadedFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UploadedFile类属于命名空间,在下文中一共展示了UploadedFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: InsertFile

        public override void InsertFile(UploadedFile file)
        {
            UploadStorageDataContext db = new UploadStorageDataContext(ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString);

            Table<LinqUploadedFile> files = db.GetTable<LinqUploadedFile>();

            file.ApplicationName = this.ApplicationName;

            files.InsertOnSubmit(new LinqUploadedFile(file));

            try
            {
                db.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (ChangeConflictException ex)
            {
                Trace.TraceError(ex.Message);

                // All database values overwrite current values.
                foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    occ.Resolve(RefreshMode.OverwriteCurrentValues);
            }
            catch (DbException ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
开发者ID:kohku,项目名称:codefactory,代码行数:27,代码来源:LinqUploadStorageProvider.cs


示例2: LoadFilesForTesting

		/// <summary>
		/// Load all files stored in Storage
		/// </summary>
		/// <returns></returns>
		public static List<UploadedFile> LoadFilesForTesting()
		{
			List<UploadedFile> files = new List<UploadedFile>();
			// In design mode, HttpContext will be null
			if (HttpContextNull())
			{
				return files;
			}

			string[] configFiles = Directory.GetFiles(HttpContext.Current.Server.MapPath(appDataPath), "*" + configExtension);
			foreach (string config in configFiles)
			{
				FileInfo configFile = new FileInfo(config);
				string fileId = configFile.Name.Substring(0, configFile.Name.LastIndexOf("."));
				FileInfo originalFile = new FileInfo(FileId2FullName(fileId));

				if (originalFile.Exists)
				{
					UploadedFile fileItem = new UploadedFile();
					fileItem.Id = fileId;
					fileItem.Filename = File.ReadAllText(config);
					fileItem.Size = originalFile.Length;
					fileItem.LastModified = originalFile.LastWriteTime;

					files.Add(fileItem);
				}
			}
			return files;
		}
开发者ID:jijiechen,项目名称:ASP.NET-Output-Files-With-NonAsciiFilenames,代码行数:33,代码来源:FileStorage.cs


示例3: GetInputStream

    public override Stream GetInputStream(UploadedFile file)
    {
        FileStream fileS = null;
        ZipInputStream zipS = null;

        try
        {
            string path = GetZipPath(file);

            fileS = File.OpenRead(path);
            zipS = new ZipInputStream(fileS);

            zipS.GetNextEntry();

            return zipS;
        }
        catch
        {
            if (fileS != null)
                fileS.Dispose();

            if (zipS != null)
                zipS.Dispose();

            return null;
        }
    }
开发者ID:bmsolutions,项目名称:mvc2inaction,代码行数:27,代码来源:ZipUploadStreamProviderCS.cs


示例4: btnSubmit_Click

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid) return;
        if (!Permission.Check("file.create", false)) return;

        string fileName = Resources.Moo.File_UploadPath + Path.GetRandomFileName() + "." + fileUpload.FileName.Split('.').Last();
        fileUpload.SaveAs(fileName);
        int fileID;
        using (MooDB db = new MooDB())
        {
            User currentUser = ((SiteUser)User.Identity).GetDBUser(db);
            UploadedFile file = new UploadedFile()
            {
                Name = txtName.Text,
                Description = txtDescription.Text,
                Path = fileName,
                CreatedBy=currentUser
            };
            db.UploadedFiles.AddObject(file);
            db.SaveChanges();
            fileID = file.ID;

            Logger.Info(db, "创建文件#" + fileID);
        }

        PageUtil.Redirect("创建成功", "~/File/?id=" + fileID);
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:27,代码来源:Create.aspx.cs


示例5: GetOutputStream

    public override Stream GetOutputStream(UploadedFile file)
    {
        FileStream fileS = null;
        ZipOutputStream zipS = null;

        try
        {
            string outputPath = GetZipPath(file);

            Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

            fileS = File.OpenWrite(outputPath);
            zipS = new ZipOutputStream(fileS);

            zipS.SetLevel(5);

            zipS.PutNextEntry(new ZipEntry(file.ClientName));

            file.LocationInfo[FileNameKey] = outputPath;

            return zipS;
        }
        catch
        {
            if (fileS != null)
                fileS.Dispose();

            if (zipS != null)
                zipS.Dispose();

            return null;
        }
    }
开发者ID:bmsolutions,项目名称:mvc2inaction,代码行数:33,代码来源:ZipUploadStreamProviderCS.cs


示例6: ExportOneSkyTranslationWithRetry

	private UploadedFile.ExportTranslationState ExportOneSkyTranslationWithRetry(UploadedFile OneSkyFile, string Culture, MemoryStream MemoryStream)
	{
		const int MAX_COUNT = 3;

		long StartingMemPos = MemoryStream.Position;
		int Count = 0;
		for (;;)
		{
			try
			{
				return OneSkyFile.ExportTranslation(Culture, MemoryStream).Result;
			}
			catch (Exception)
			{
				if (++Count < MAX_COUNT)
				{
					MemoryStream.Position = StartingMemPos;
					Console.WriteLine("ExportOneSkyTranslation attempt {0}/{1} failed. Retrying...", Count, MAX_COUNT);
					continue;
				}

				Console.WriteLine("ExportOneSkyTranslation attempt {0}/{1} failed.", Count, MAX_COUNT);
				break;
			}
		}

		return UploadedFile.ExportTranslationState.Failure;
	}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:28,代码来源:OneSkyLocalizationProvider.cs


示例7: InsertImage

        public int InsertImage(UploadedFile file, int userID)
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TelerikConnectionString35"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                string cmdText = "INSERT INTO AsyncUploadImages VALUES(@ImageData, @ImageName, @UserID) SET @Identity = SCOPE_IDENTITY()";
                SqlCommand cmd = new SqlCommand(cmdText, conn);

                byte[] imageData = GetImageBytes(file.InputStream);

                SqlParameter identityParam = new SqlParameter("@Identity", SqlDbType.Int, 0, "ImageID");
                identityParam.Direction = ParameterDirection.Output;

                cmd.Parameters.AddWithValue("@ImageData", imageData);
                cmd.Parameters.AddWithValue("@ImageName", file.GetName());
                cmd.Parameters.AddWithValue("@UserID", userID);

                cmd.Parameters.Add(identityParam);

                conn.Open();
                cmd.ExecuteNonQuery();

                return (int)identityParam.Value;
            }
        }
开发者ID:selva-osai,项目名称:scheduler,代码行数:26,代码来源:VideoUploadT1.ashx.cs


示例8: upload_button_click

        protected void upload_button_click(object sender, EventArgs e)
        {
            if (file_upload_control.HasFile)
            {
                try
                {
                    UploadedFile uf = new UploadedFile(file_upload_control.PostedFile);

                    foreach (PropertyInfo info in uf.GetType().GetProperties())
                    {
                        TableRow row = new TableRow();

                        TableCell[] cells = new TableCell[] {new TableCell(),new TableCell(),new TableCell()};
                        cells[0].Controls.Add(new LiteralControl(info.PropertyType.ToString()));
                        cells[1].Controls.Add(new LiteralControl(info.Name));
                        cells[2].Controls.Add(new LiteralControl(info.GetValue(uf).ToString()));
                        row.Cells.AddRange(cells);

                        file_upload_details_table.Rows.Add(row);
                    }

                    status_label.Text = "Status: OK!";
                }
                catch (Exception ex)
                {
                    status_label.Text = "Status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
开发者ID:ThijsVredenbregt,项目名称:applab7,代码行数:29,代码来源:Default.aspx.cs


示例9: SavePostedFile

        private void SavePostedFile(UploadedFile uploadedFile)
        {
            if (!uploadedFile.IsValid)
                return ;

            var fileOriginalName = uploadedFile.FileName;

            int index;
                for (index = 0; index < UploadControlBudges.UploadedFiles.Length; index++)
                {
                    if (UploadControlBudges.UploadedFiles[index].FileName == fileOriginalName)
                    {
                        break;
                    }
                }
            if (index == 0)
            {
                _fileGroupId = _dal.RegisterNewBadgesFileGroup(tbBadgeGroupName.Text, tbMessage.Text, TbDescription.Text, cbImageType.Text, Convert.ToInt32(cbGrantRule.SelectedItem.Value));
            }

            var guid = Guid.NewGuid();

            string fileName = Path.Combine(MapPath(UploadDirectory), guid.ToString() + ".png");
            uploadedFile.SaveAs(fileName, true);
            _dal.RegisterNewBadgeInFileGroup(_fileGroupId, guid, index);
        }
开发者ID:Letractively,项目名称:dc-gamification,代码行数:26,代码来源:ManageBadges.ascx.cs


示例10: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Permission.Check("file.read", true)) return;

        if (!Page.IsPostBack)
        {
            using (MooDB db = new MooDB())
            {
                if (Request["id"] != null)
                {
                    int fileID = int.Parse(Request["id"]);
                    file = (from f in db.UploadedFiles
                            where f.ID == fileID
                            select f).SingleOrDefault<UploadedFile>();
                }

                if (file == null)
                {
                    PageUtil.Redirect(Resources.Moo.FoundNothing, "~/");
                    return;
                }

                Page.DataBind();
            }
        }
    }
开发者ID:MooDevTeam,项目名称:MooOJ,代码行数:26,代码来源:Default.aspx.cs


示例11: CloseWriteStream

        /// <inheritdoc />
        /// <summary>
        /// Overridden. <inherited />
        /// </summary>
        public override void CloseWriteStream(UploadedFile file, Stream stream, bool isComplete)
        {
            if (!isComplete)
                stream.Dispose();

            // We actually want to leave the stream open so we can read from it later if it is complete
            stream.Seek(0, SeekOrigin.Begin);
        }
开发者ID:codingbat,项目名称:BandCamp,代码行数:12,代码来源:MemoryUploadStreamProvider.cs


示例12: RemoveOutput

        /// <inheritdoc />
        /// <summary>
        /// Overridden. <inherited />
        /// </summary>
        public override void RemoveOutput(UploadedFile file)
        {
            // Upload was cancelled or errored, so we need to remove and dispose the stream
            MemoryStream s = (MemoryStream)HttpContext.Current.Application[file.ServerLocation];

            if (s != null)
                s.Dispose();

            HttpContext.Current.Application.Remove(file.ServerLocation);
        }
开发者ID:codingbat,项目名称:BandCamp,代码行数:14,代码来源:MemoryUploadStreamProvider.cs


示例13: Process

        protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
        {
            telerikAsyncUploadResult result = CreateDefaultUploadResult<telerikAsyncUploadResult>(file);
            string folderType = "temp";
            DocAccess objDoc = new DocAccess();

            result.DocumentID = 0;
            result.DocumentID = objDoc.saveFiles(file, folderType, Convert.ToInt32(context.Session["ClientID"]), Convert.ToInt32(context.Session["UserID"]), 0, Convert.ToInt32(context.Session["WebinarID"]));
            return result;
        }
开发者ID:selva-osai,项目名称:scheduler,代码行数:10,代码来源:CropUpload.ashx.cs


示例14: ReadFromStreamAsync

 public override async Task<object> ReadFromStreamAsync(Type type,
                                                        Stream readStream,
                                                        HttpContent content,
                                                        IFormatterLogger formatterLogger,
                                                        CancellationToken cancellationToken)
 {
     var uf = new UploadedFile(StrHelper.UnquoteToken(content.Headers.ContentDisposition.FileName),
                               await content.ReadAsStreamAsync());
     return uf;
 }
开发者ID:riberk,项目名称:Rib.Common,代码行数:10,代码来源:StreramMediaTypeFormatter.cs


示例15: GetReadStream

        /// <inheritdoc />
        /// <summary>
        /// Overridden. <inherited />
        /// </summary>
        public override Stream GetReadStream(UploadedFile file)
        {
            MemoryStream s = (MemoryStream)HttpContext.Current.Application[file.ServerLocation];

            // Remove the stream from application state. This means GetReadStream can only be called once per file, but ensures that
            // app state remains clean

            HttpContext.Current.Application.Remove(file.ServerLocation);

            return s;
        }
开发者ID:codingbat,项目名称:BandCamp,代码行数:15,代码来源:MemoryUploadStreamProvider.cs


示例16: ProcessVideo

    //private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file)
    //{
    //    const int total = 100;

    //    RadProgressContext progress = RadProgressContext.Current;

    //    for (int i = 0; i < total; i++)
    //    {
    //        progress["PrimaryTotal"] = total.ToString();
    //        progress["PrimaryValue"] = i.ToString();
    //        progress["PrimaryPercent"] = i.ToString();
    //        progress["CurrentOperationText"] = file.GetName() + " is being processed...";

    //        if (!Response.IsClientConnected)
    //        {
    //            //Cancel button was clicked or the browser was closed, so stop processing
    //            break;
    //        }

    //        //Stall the current thread for 0.1 seconds
    //        System.Threading.Thread.Sleep(100);
    //    }
    //}

    public void ProcessVideo(UploadedFile VideoFile)
    {
        litCompleted.Text = "";
        try
        {
            member = (Member)Session["Member"];
            bool ValidExtention = true;
            string VideoTitle = string.Empty;
            string Ext = string.Empty;

            Video video = new Video();

            video.Title = (txtTitle.Text != "") ? txtTitle.Text : "New video";
            video.Description = (txtCaption.Text != "") ? txtCaption.Text : "No Description"; 

            try
            {
                Ext = VideoFile.GetExtension();
            }
            catch
            {
                Ext = "xxx";
                ValidExtention = false;
            }

            Ext = Ext.Replace(".", "");

            // upload the flv
            if (IsVideo(Ext))
            {
                if (VideoFile.ContentLength > 150000)
                {
                    Video.QueueVideoForEncoding(video, VideoFile.InputStream, Ext, member, VideoTitle);
                    litCompleted.Text = "<script>parent.location.href='MyVideoGallery.aspx?p=1';</script><img src='images/check.gif'/>&nbsp;&nbsp; Your video was successfully uploaded ";
                }
                else
                {
                    litCompleted.Text = "<img src='images/na.gif'/>&nbsp;&nbsp;Your video must be at least 2 seconds long";
                }
            }
            else
            {
                if (ValidExtention)
                    litCompleted.Text = "<img src='images/na.gif'/>&nbsp;&nbsp;Videos with the extention <strong>" + Ext + "</strong> arent supported";
                else
                    litCompleted.Text = "<img src='images/na.gif'/>&nbsp;&nbsp;Videos files must have an extention name. For example: .avi or .mov";
            }
        }
        catch(Exception ex)
        {
            string MachineName = Environment.MachineName;
            Next2Friends.Data.Trace.Tracer(ex.ToString(), "RadVideoUpload");
        }
    }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:78,代码来源:UploadVideo2.aspx.cs


示例17: SavePostedFile

 public static string SavePostedFile(UploadedFile uploadedFile)
 {
     string ret = "";
     if (uploadedFile.IsValid)
     {
         string fileToSave = FileUtils.GetUploadedFileLocalName(uploadedFile.FileName);
         uploadedFile.SaveAs(fileToSave);
         ret = fileToSave;
     }
     return ret;
 }
开发者ID:ddksaku,项目名称:canon,代码行数:11,代码来源:FileUtils.cs


示例18: AddFile

        public void AddFile(UploadedFile file, string fileUploadContext)
        {
            string folder = GetUploadPath(fileUploadContext);
            if (!Directory.Exists(folder))
                Directory.CreateDirectory(folder);

            FileStream fs = File.Create(Path.Combine(folder, file.FileName), file.ContentLength);
            byte[] buffer = new byte[(int)file.InputStream.Length];
            file.InputStream.Read(buffer, 0, (int)file.InputStream.Length);
            fs.Write(buffer, 0, buffer.Length);
            fs.Close();
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:12,代码来源:UploadFileManager.cs


示例19: GetWriteStream

        /// <inheritdoc />
        /// <summary>
        /// Overridden. <inherited />
        /// </summary>
        public override Stream GetWriteStream(UploadedFile file)
        {
            // Create a stream
            MemoryStream s = new MemoryStream();
            string key = Guid.NewGuid().ToString();

            // Store it for later
            file.ServerLocation = key;
            HttpContext.Current.Application[file.ServerLocation] = s;

            return s;
        }
开发者ID:codingbat,项目名称:BandCamp,代码行数:16,代码来源:MemoryUploadStreamProvider.cs


示例20: GetObjectName

 /// <summary>
 /// Returns the object name to use for a given <see cref="UploadedFile" />.
 /// </summary>
 /// <param name="file">The <see cref="UploadedFile" /> for which to generate an object name.</param>
 /// <returns>The generated object name.</returns>
 public virtual string GetObjectName(UploadedFile file)
 {
     switch (_objectNameMethod)
     {
         default:
         case ObjectNameMethod.Client:
             return file.ClientName;
         case ObjectNameMethod.Guid:
             return Guid.NewGuid().ToString("n");
         case ObjectNameMethod.GuidWithExtension:
             return Guid.NewGuid().ToString("n") + Path.GetExtension(file.ClientName);
     }
 }
开发者ID:codingbat,项目名称:BandCamp,代码行数:18,代码来源:S3UploadStreamProvider.cs



注:本文中的UploadedFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UploadersConfig类代码示例发布时间:2022-05-24
下一篇:
C# UploadResult类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap