나는 무엇을 대신 사용자.값이 있습니다.추가(...에 대한 ListViewEditEventArgs 이미지를 업로드하는

StackOverflow https://stackoverflow.com/questions/250528

문제

나는 이미지를 업로드 할 수 있습 데이터베이스를 사용하여 linq 및 listview 컨트롤 때 referancing e.값을 위한 방법 ListViewInsertEventArgs,그러나 그런 방법에 ListViewEditEventArgs,그래서 무엇을 사용할 수 있습니 같은 결과를 얻기 위해?

여기에 나를 삽입하는 코드:

protected void ProjectPhotosList_ItemInserting(객체를 보낸 사람,ListViewInsertEventArgs e)

{

FileUpload uplImage=(FileUpload)ProjectPhotosList.InsertItem.FindControl("uplImage");

라벨 fileuploadlbl=(레이블)ProjectPhotosList.InsertItem.FindControl("fileuploadlbl");

    byte[] img = null;
    if (uplImage.HasFile || !uplImage.FileName.ToLower().EndsWith(".jpg"))
    {
        try
        {
            img = new byte[uplImage.PostedFile.ContentLength];
            uplImage.PostedFile.InputStream.Read(img, 0, img.Length);
        }
        catch
        {
            fileuploadlbl.Text = "unable to upload " + uplImage.FileName.ToString();
        }
    }
    if (img == null)
    {
        e.Cancel = true;
        fileuploadlbl.Text = "Please choose a file to upload";
    }

    try
    {
        e.Values.Add("ProjectPhoto", new System.Data.Linq.Binary(img));
        fileuploadlbl.Text = "File Upload Successful";
    }
    catch
    {
        fileuploadlbl.Text = "File Upload Failed, please try again";
    }
}
도움이 되었습니까?

해결책

ok 그래서 저는 이 문제를 해결!나는 그냥 그것에 대해 이동하는 비트의 다른 방법:

이것은 중요한 코드:

int 다.=int.Parse(ProjectPhotosList.DataKeys[e.ItemIndex].값이 있습니다.ToString());

그냥 간단한 방법으의 값을 선택한다.내가 찾는 게시물에 대해 업로드 pdf 의 데이터베이스하기로 결정하는 기본의 나머지 부분 나의 코드입니다.그래서 여기서는 전체 코드:

protected void ProjectPhotosList_ItemUpdating(객체를 보낸 사람,ListViewUpdateEventArgs e)

{

FileUpload myFile=(FileUpload)ProjectPhotosList.EditItem.FindControl("uploadImage");

    TextBox myCaption = (TextBox)ProjectPhotosList.EditItem.FindControl("ProjectPhotoCaptionTextBox");

    int mykey = int.Parse(ProjectPhotosList.DataKeys[e.ItemIndex].Value.ToString());

    if (myFile.HasFile)
    {

        //Get the posted file
        Stream fileDataStream = myFile.PostedFile.InputStream;

        //Get length of file
        int fileLength = myFile.PostedFile.ContentLength;

        //Create a byte array with file length
        byte[] fileData = new byte[fileLength];

        //Read the stream into the byte array
        fileDataStream.Read(fileData, 0, fileLength);

        //get the file type
        string fileType = myFile.PostedFile.ContentType;

        //Open Connection
        PHJamesDataContext db = new PHJamesDataContext();
        //Find the Right Row
        PHJProjectPhoto Newphoto = (from p in db.PHJProjectPhotos
                                    where p.ProjectPhotoId == mykey
                                    select p).Single<PHJProjectPhoto>();


        Newphoto.ProjectPhoto = fileData;

        db.SubmitChanges();
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top