当前位置: 首页>>代码示例>>C#>>正文


C# UploadedFile类代码示例

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


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


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