SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error in multiplefile attachment

    hi,
    i m getting error in multiplefile attachment.
    for attachment fields are:
    document_id(number)
    document_name(varchar2)
    document(blob)

    here is my code:
    OracleConnection cn = null;
    OracleCommand cmd = null;

    String connectionString = "Data Source=TEST01;User id=IMS; Password=IMS;";
    cn = new OracleConnection(connectionString);
    Byte[] attach1 = new Byte[0];
    Byte[] imgByte1 = null;
    Byte[] attach2 = new Byte[0];
    Byte[] imgByte2 = null;
    Byte[] attach3 = new Byte[0];
    Byte[] imgByte3 = null;
    String name1 = null;
    String name2 = null;
    String name3 = null;

    cn.Open();


    createdby = Session["USERNAME"].ToString();
    String query;
    query = "insert into ims_document(document_id,document_name,document);";
    query += " values document_id,:document_name";
    query += ":document)";
    cmd = new OracleCommand(query,cn);


    cmd.Parameters.Add(":document_id", OracleType.Number).Value=1;
    cmd.Parameters.Add(":document_name", OracleType.VarChar).Value = name1;
    cmd.Parameters.Add(":document", OracleType.Blob).Value = attach1;

    cmd.ExecuteNonQuery();

    i m geting value of attach1,attach2.... bt it is not storing in the database.
    even cmd.parameters is giving null value.

    plz can any one help me for this.

  2. #2
    Non-Member adstiger's Avatar
    Join Date
    Nov 2008
    Location
    Canada
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Insert a break point and test on the attachment function call.

    May this article can help you:
    http://www.jobscat.com/search/index....ttachment+.NET

  3. #3
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by yogita View Post
    hi,



    String connectionString = "Data Source=TEST01;User id=IMS; Password=IMS;";


    query = "insert into ims_document(document_id,document_name,document);";

    First check your connection string is it right?
    and second in your insert query there is one extra ; before " so remove it write like

    insert into ims_document(document_id,document_name,document)";

    May be your problem will solve

    thanks,
    kunalraj
    Last edited by kunalraj; Mar 11, 2009 at 23:05.

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks kunal....

    i already got the solution.

    here is my solution:
    bool InsertDocuments(byte[] attach, string docName, string docType, string docExt, string incidentId)
    {
    DataAccess objAccess = new DataAccess();
    string query = "";
    string documentId = "0";
    OracleParameter[] param = new OracleParameter[1];

    try
    {
    query = "SELECT IMS_DOCUMENT_ID_SQ.NEXTVAL FROM DUAL";
    documentId = objAccess.getScalarValue(query).ToString();
    for (int i = 0; i < param.Length; i++)
    {
    param[i] = new OracleParameter();
    }
    query = "INSERT INTO IMS_DOCUMENT (DOCUMENT_ID,DOCUMENT_NAME,DOCUMENT_TYPE,DOCUMENT_EXT";
    query += ",INCIDENT_ID,DOCUMENT) values (" + documentId + ",'" + docName + "','";
    query += docType + "','" + docExt + "','" + incidentId + "',:doc)";

    param[0].ParameterName = "doc";
    param[0].Direction = ParameterDirection.Input;
    param[0].OracleType = OracleType.Blob;
    param[0].Value = attach;



    return objAccess.doUpdateInsert(query, param);
    }

  5. #5
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok



    thanks,
    kunalraj

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nw i want to give max size not more than 4 MB for any file attachment. how to give ths???

  7. #7
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    For that you have to write some code into web.config file.
    you want to max upload 4 mb for individual file upload or for all(3) files upload size 4mb?

    For 3upload and max size 12 mb you have to write in web.config file

    <configuration>
    <system.web>
    <httpRuntime maxRequestLength="12288" requestLengthDiskThreshold="100"/>

    <!-- DYNAMIC DEBUG COMPILATION
    Set compilation debug="true" to enable ASPX debugging. Otherwise, setting this value to
    false will improve runtime performance of this application.
    Set compilation debug="true" to insert debugging symbols (.pdb information)
    into the compiled page. Because this creates a larger file that executes
    more slowly, you should set this value to true only when debugging and to
    false at all other times. For more information, refer to the documentation about
    debugging ASP.NET files.
    -->
    <compilation defaultLanguage="c#" debug="true">


    in above 12288 represents size in kb. so its calculation in mb is 12288kb=12mb.
    you can set it as per your requi. whatever you want in mb you have to write in kb.


    thanks,
    kunalraj

  8. #8
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    requestLengthDiskThreshold="100" whats the meaning of this ?

  9. #9
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by yogita View Post
    requestLengthDiskThreshold="100" whats the meaning of this ?


    hi,

    i am not sure but 99% it showing the time in minute.
    Means in 100 min your 4mb or 12 mb file not uploaded than it will lost connection or intrupted your upload files.



    thanks,
    kunalraj

  10. #10
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I Want to give for individual file. if user select 1st file thn it does not contain more than 4mb. same for 2nd file and 3rd file

  11. #11
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,


    for that you have to write total size if 3 upload than 12288in web.config and write some code into your hard code.

    In your uploading code you have to write like
    for (int i = 0; i < Request.Files.Count; i++)
    {
    HttpPostedFile file = Request.Files[i] as HttpPostedFile;

    if (i == 0)
    {
    int attachFileLength = file.ContentLength;
    if (attachFileLength > 0 && attachFileLength < 4096)
    {
    String pathname = file.FileName;
    int totlen = pathname.Length;
    int slash = pathname.LastIndexOf('\\');
    int dot = pathname.LastIndexOf('.');
    int start = slash + 1;
    int len = (dot - start);
    int end = dot + 1;
    int ending = totlen - end;
    name1 = pathname.Substring(start, len);
    ext1 = pathname.Substring(end, ending);
    imgByte1 = new Byte[file.ContentLength];
    file.InputStream.Read(imgByte1, 0, file.ContentLength);
    attach1 = imgByte1;


    above bold latter you have to add in your code check it.


    thanks,
    kunalraj.

  12. #12
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i m attaching the file size of 23.5 kb so attachfilelength >0 is 24064 so as per your code its not taking file attachment bcoz attachmentfilelenght<4096.
    so wht to define in attachmentfilelenght<?

  13. #13
    SitePoint Addict kunalraj's Avatar
    Join Date
    Nov 2008
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by yogita View Post
    i m attaching the file size of 23.5 kb so attachfilelength >0 is 24064 so as per your code its not taking file attachment bcoz attachmentfilelenght<4096.
    so wht to define in attachmentfilelenght<?
    in your project 3 upload so in all condition

    if (i == 0)
    {
    int attachFileLength = file.ContentLength;
    if (attachFileLength > 0 && attachFileLength < 4096)
    {
    String pathname = file.FileName;
    ...................

    else if (i == 1)
    {
    int attachFileLength = file.ContentLength;
    if (attachFileLength > 0 && attachFileLength < 4096)
    {
    String pathname = file.FileName;
    .........

    else if (i == 2)
    {
    int attachFileLength = file.ContentLength;
    if (attachFileLength > 0 && attachFileLength < 4096)
    {
    String pathname = file.FileName;


    you have to write
    that && attachFileLength < 4096

    check it and check 23.5 kb so attachfilelength >0 is 24064
    24064 is kb and 23.5mb not 23.5kb check your file size it is in mb not in kb.


    thanks,
    kunalraj
    Last edited by kunalraj; Mar 13, 2009 at 01:43.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •