我使用了这段代码:
string oldRelID = part.GetIdOfPart(imagePart);
foreach (XmlElement list in pictureNodeList)
{
XmlNodeList elementList = list.GetElementsByTagName("a:blip");
foreach (XmlNode node in elementList)
{
foreach (XmlAttribute att in node.Attributes)
{
if (att.Value == oldRelID)
{
XmlNodeList trevList = list.GetElementsByTagName("p:cNvPr");
foreach (XmlNode trevnode in trevList)
{
foreach (XmlAttribute trevatt in trevnode.Attributes)
{
if (trevatt.Name == "descr")
{
mapReference = trevatt.Value;
}
}
}
}
}
}
}
如果我使用下面的代码保留真实的文件名,它将无需双重发布:
Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AsyncFileUpload1.UploadedComplete
Try
Dim UploadFolderPath As String = "~/Site/Files/"
Dim fileext As String = System.IO.Path.GetExtension(AsyncFileUpload1.FileName)
Dim file_id As String = Guid.NewGuid().ToString()
AsyncFileUpload1.SaveAs(Server.MapPath(UploadFolderPath) + file_id + fileext)
Catch ex As Exception
Throw ex
End Try
End Sub
这是页面来源:
Dim savePath As String = MapPath("Files/" & Path.GetFileName(e.FileName))
AsyncFileUpload1.SaveAs(Server.MapPath(savePath) )
asynfileupload控件:
<script type="text/javascript">
function clearContents() {
var span = $get("<%=AsyncFileUpload1.ClientID%>");
var txts = span.getElementsByTagName("input");
for (var i = 0; i < txts.length; i++) {
if (txts[i].type == "text") {
txts[i].value = "";
}
if (txts[i].type == "file") {
txts[i].value = "";
}
}
}
function uploadStarted(sender, args) {
if (args.get_length() > 1048576) {
$get("<%=AsyncFileUpload1.ClientID%>").style.display = 'block';
$get("dvFileErrorInfo").style.display = 'block';
$get("dvFileInfo").style.display = 'none';
$get("<%=lblError.ClientID%>").innerHTML = "حجم الملف تجاوز الحد المسموح به 2 ميجابايت "
} else {
$get("<%=AsyncFileUpload1.ClientID%>").style.display = 'none';
$get("dvFileErrorInfo").style.display = 'none';
$get("dvFileInfo").style.display = 'none';
}
}
function uploadError(sender, args) {
try {
$get("<%=AsyncFileUpload1.ClientID%>").style.display = 'block';
$get("dvFileErrorInfo").style.display = 'block';
$get("dvFileInfo").style.display = 'none';
$get("<%=lblError.ClientID%>").innerHTML = "لم يتم رفع الملف : " + args.get_errorMessage();
}
catch (e) {
}
}
function uploadComplete(sender, args) {
try {
$get("<%=AsyncFileUpload1.ClientID%>").style.display = 'block';
var filename = args.get_fileName();
var ext = filename.substring(filename.lastIndexOf(".") + 1);
document.getElementById('<%= FileExt.ClientID %>').value = ext;
if (ext != 'zip' && ext != 'rar' && ext != 'doc' && ext != 'docx' && ext != 'pdf' && ext != 'RAR') {
document.getElementById("errmsg").innerHTML = ext;
$get("dvFileErrorInfo").style.display = 'block';
$get("<%=lblError.ClientID%>").innerHTML = "صيغة الملف ليست مدعومة، يسمح لك فقط برفع الملفات التالية: مستند مايكروسوفت وود - وثيقة أكروبات - ملف مضغوط";
$get("dvFileInfo").style.display = 'none';
return;
}
$get("dvFileInfo").style.display = 'block';
$get("dvFileErrorInfo").style.display = 'none';
$get("<%=lblSuccess.ClientID%>").innerHTML = "تم رفع الملف بنجاح";
$get("<%=lblFileNameDisplay.ClientID%>").innerHTML = args.get_fileName();
$get("<%=lblFileSizeDisplay.ClientID%>").innerHTML = args.get_length() /1024 + " كيلو بايت";
$get("<%=lblContentTypeDisplay.ClientID%>").innerHTML = args.get_contentType();
}
catch (e) {
//alert(e.message);
}
}
</script>
隐藏的文件是捕获文件扩展名,
#