c# - 在 C# 中上传到 SQL Server 之前重命名文件名?
问题描述
在将文件上传到 SQL Server 之前,如何在 C# 中重命名文件?
我试过这个:
if (n.HasFile)
{
string fileNameWithoutExtension=Path .GetFileNameWithoutExtension(CapitalStructureShareHoldingFile.FileName);
string extension = Path.GetExtension(n.FileName);
fileNameWithoutExtension = "n" + extension;
}
对于这个文件,我想将它重命名为n
它的扩展名。
解决方案
if (ASPxUploadControl1.HasFile ) or//(Fileupload.Hasfile)
{
try
{
string extension = Path.GetExtension(ASPxUploadControl1.FileName);
string id = Guid.NewGuid().ToString(); //here give your username or whatever you want
string fileLocation = string.Format("{0}/{1}{2}", Server.MapPath("upload/"), id, extension);
ASPxUploadControl1.SaveAs( fileLocation );
StatusLabel.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
推荐阅读
- python - OpenCV 捕获多个 RTSP 流 - Python
- facebook - 本机脚本 facebook//google sso 服务器端
- php - 从动态图片 url 获取图片扩展
- html - 为什么刷新浏览器时无法显示pdf文件?
- android - 使用 MainActivity.java 文件和 Window.java 文件创建一个窗口 HelloWorld 应用程序
- jwt - 基于令牌的身份验证:将路由限制为特定用户
- node.js - Puppeteer chrome 允许多个文件下载
- mongodb - 副本集重新配置在 mongo 中不起作用
- javascript - lodash.differenceBy 在香草 JavaScript 中?
- python - Scipy稀疏矩阵行广播