本文整理汇总了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);
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
}
示例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);
}
示例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();
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}