Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用会话变量更改文件名_Javascript_C#_Asp.net - Fatal编程技术网

Javascript 使用会话变量更改文件名

Javascript 使用会话变量更改文件名,javascript,c#,asp.net,Javascript,C#,Asp.net,我有下面的代码,工作正常,但我想用session(“MyFileName”)变量值更改文件名,我不知道如何编辑 function onUploadClick() { if (fileUpload.value.length > 0) { var filename = fileExists(); if (filename == '') { //Update the message updateMessage(MessageStatus.Infor

我有下面的代码,工作正常,但我想用session(“MyFileName”)变量值更改文件名,我不知道如何编辑

function onUploadClick() {
if (fileUpload.value.length > 0) {
    var filename = fileExists();
    if (filename == '') {
        //Update the message
        updateMessage(MessageStatus.Information, 'Initializing upload ...', '', '0 of 0 Bytes');
        //Submit the form containing the fileupload control
        form.submit();
        //Set transparancy 20% to the frame and upload button
        Sys.UI.DomElement.addCssClass($get('dvUploader'), 'StartUpload');
        //Initialize progressbar
        setProgress(0);
        //Start polling to check on the progress ...
        startProgress();
        intervalID = window.setInterval(function() {
        PageMethods.GetUploadStatus(function(result) {
            if (result) {
                setProgress(result.percentComplete);
                //Upadte the message every 500 milisecond
                updateMessage(MessageStatus.Information, result.message, result.fileName, result.downloadBytes);
                if (result == 100) {
                    //clear the interval
                    window.clearInterval(intervalID);
                    clearTimeout(subintervalID);
                }
            }
        });
        }, 500);
    }
    else
        onComplete(MessageStatus.Error, "File name '<b>" + filename + "'</b> already exists in the list.", '', '0 of 0 Bytes');
}
else
    onComplete(MessageStatus.Warning, 'You need to select a file.', '', '0 of 0 Bytes');
}
函数onUploadClick(){
如果(fileUpload.value.length>0){
var filename=fileExists();
如果(文件名=“”){
//更新消息
updateMessage(MessageStatus.Information,'Initializing upload…','0/0字节');
//提交包含fileupload控件的表单
表单提交();
//将“帧和上载”按钮的透明度设置为20%
Sys.UI.domeElement.addCssClass($get('dvUploader'),'StartUpload');
//初始化进度条
setProgress(0);
//开始轮询以检查进度。。。
startProgress();
intervalID=window.setInterval(函数(){
PageMethods.GetUploadStatus(函数(结果){
如果(结果){
设置进度(结果完成百分比);
//每500毫秒更新一次消息
updateMessage(MessageStatus.Information、result.message、result.fileName、result.downloadBytes);
如果(结果==100){
//清除间隔
窗口。clearInterval(intervalID);
clearTimeout(次有效);
}
}
});
}, 500);
}
其他的
onComplete(MessageStatus.Error,“文件名””+filename+“”已存在于列表中。“,”,“0/0字节”);
}
其他的
onComplete(MessageStatus.Warning,'您需要选择一个文件','',0个字节');
}

如果文件存在,我还需要替换它。

这是webforms还是Razor?在webforms中使用
var filename='
,在Razor中使用
var filename='@Session[“MyFileName”].ToString()'
。它是Webform。我不知道在哪里实施你的建议:(fileExists()的内容是什么)?好吧,在
fileUpload.value.length
检查之后放置
var filename='';
就足够了。我仍然不明白的是,如果文件存在,您希望如何替换它。这是实际的源代码链接@John,感谢您的修改和提示。