2012-09-18 2 views
0

서버 sidecodeAsyncFileUpload

protected void UploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) 
{ 
    rlativepath =GeneratePrefixFileName() + AsyncFileUpload1.PostedFile.FileName; 
    databasepath = "~/Image/" + rlativepath; 
    filePath = Request.PhysicalApplicationPath + "image\\"+rlativepath; 
    AsyncFileUpload1.SaveAs(filePath); 
} 

클라이언트 측 코드를 사용하는 동안 서버 측 클라이언트 측에서 파일 이름을 이름 바꾸기를 얻는 방법

<script type="text/javascript"> 

function upLoadStarted() { 
    $get("imgDisplay").style.display = "none"; 
} 
function showConfirmation(sender, args) { 
    var txt = document.getElementById('<%=statusoutput.ClientID %>'); 
    var img = document.getElementById('<%=statusoutput.ClientID %>'); 
    txt.value = "Upload Successful"; 

    var imgDisplay = $get("imgDisplay"); 
    imgDisplay.src = "ajaxupload.jpg"; 
    imgDisplay.style.cssText = "height:100px;width:100px"; 
    var img = new Image(); 
    img.onload = function() { 
     imgDisplay.style.cssText = "height:100px;width:100px"; 
     imgDisplay.src = img.src; 
    }; 
    <%# UploadFolderPath1+=rlativepath %> 
    img.src = "<%=ResolveUrl(UploadFolderPath1) %>"+ args.get_fileName(); 
    alert(img.src); 
    var imagedescrip = $get("imagedescrip"); 
    imagedescrip.style.cssText = "visibility:visible;"; 
    } 

aspx 페이지 : I가 AsyncFileUpload을 사용하고

<asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
     content of page 
    FNever increase, beyond what is necessary, the number of entities required to explain anything." William of Ockham (1285-1349) 
    <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnUploadedComplete="UploadComplete" ThrobberID="imgLoader" OnClientUploadStarted="upLoadStarted" UploaderStyle="Modern" OnClientUploadComplete="showConfirmation" 
    Width="400px" CompleteBackColor="White" UploadingBackColor="#CCFFFF"></asp:AsyncFileUpload> 
    <input type="text" id="statusoutput" runat="server" readonly="readonly" tabindex="-1000" style="border:0px;background-color:transparent;" /> 
    <asp:Image ID="imgLoader" runat="server" ImageUrl="ajaxupload.jpg" Height="100px" Width="100px" /> 

    <img id = "imgDisplay" alt="" src="" style = "display:none;height:100px;width:100px"/> 

파일을 업로드, 서버에 파일을 저장하기 전에, 내가 선택한 파일의 이름을 바꿉니다. 클라이언트 측에서이 새로운 파일 이름을 얻으려면 어떻게해야합니까? 이제 내 문제는 그것을 얻으려면 클라이언트 side.how args.get_filename() 함께 이름 바꾸기 파일 이름을 얻지 못하고 있습니까?

답변

3

형태에에 HiddenField 컨트롤을 추가 : 아래

<asp:HiddenField runat="server" ID="UploadedPathHiddenField" /> 

재 작성 UploadComplete 방법 :

var src = $get("<%= UploadedPathHiddenField.ClientID %>").value; 
:

protected void UploadComplete(object sender, AsyncFileUploadEventArgs e) 
{ 
    var fileName = GeneratePrefixFileName() + System.IO.Path.GetFileName(e.FileName); 
    var relativePath = "~/Image/" + fileName; 
    var filePath = Server.MapPath(relativePath); 
    AsyncFileUpload1.SaveAs(filePath); 
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "filePath", "top.$get(\"" + UploadedPathHiddenField.ClientID + "\").value = '" + ResolveClientUrl(relativePath) + "';", true); 
} 

을 당신이에 의해 showConfirmation 방법에 저장된 이미지의 경로를 얻을 수 있습니다 후

관련 문제