locked
how to test webmethod created in asmx RRS feed

  • Question

  • User442781244 posted

    I have a wenmethod for receving pdf..so how to test it.kindly suggest

     <WebMethod()> _
    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer, ByVal USER_NAME As String)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/{1}/", USER_ID, USER_NAME)))
            If Not dinfo.Exists Then
                dinfo.Create()
            End If
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(dinfo.FullName, fileName), fileBytes)
        End Sub



    Wednesday, December 4, 2013 5:31 AM

Answers

  • User-484054684 posted

    Just create a test website and add web reference (service reference and then go to Advanced Section) - your service proxy will be created.

    Then, you can just call your webmethod like a normal method by supplying inputs.

    You may refer my earlier resolved post: http://forums.asp.net/t/1954496.aspx?Read+and+Invoke+Web+Service

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 4, 2013 5:38 AM
  • User-417640953 posted

    <WebMethod()> _
    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer, ByVal USER_NAME As String)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/{1}/", USER_ID, USER_NAME)))
            If Not dinfo.Exists Then
                dinfo.Create()
            End If
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(dinfo.FullName, fileName), fileBytes)
        End Sub

    Hi love4asp.net,

    Thank you post the issue to our forum.

    Based on your code, I see the web method is used to upload file by the users. If you want to test it, I suggest you add

    the web service reference to your client application, and create a server proxy using the server namespace.

    I made a demo for this issue.

     protected void Page_Load(object sender, EventArgs e)
            {
                string filePath = Server.MapPath("~/12-month/12-3/TestPage.pdf");
                byte[] buffer = new byte[102400]; 
                FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                stream.Read(buffer, 0, Convert.ToInt32(102400));
                NSMyWebService.MyWebserviceSoapClient proxy = new NSMyWebService.MyWebserviceSoapClient();
                proxy.GetFile(buffer,"myfile.pdf","userid","username");
            }

    You can upload a file to the server by above code. And see whether the file uploaded to server.

    For how to add web service reference to your web application, please refer to below link.

    http://msdn.microsoft.com/en-us/library/bb628649.aspx

     

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 4, 2013 9:12 PM
  • User-1509636757 posted

    Try adding Web Reference as:

    Right Click on the testing project > Add Service Reference > Click Advance button in let hand side bottom > Click on Add Web Reference in left hand side bottom > Provide the url of your asmx service > Add the Web Reference. This should add the reference of the asmx service. Then simply write the code just like you are creating the object of a class and calling the method of that class. Simply create object of your web service class and call the webmethod of that class.

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 12:50 AM
  • User-1509636757 posted

    well, I really unable to understand what is your real problem that stopping you from debugging but here is a complete solution and i tested it by passing a test pdf from test web application to the SAME web service that you have created.. http://weblogs.asp.net/blogs/kaushal/WebApplication16.zip

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 3:29 AM
  • User-1509636757 posted

       Dim web As New WebService()
            Dim filePath As String = Server.MapPath(("~/scan.pdf"))
            Dim buffer As Byte() = New Byte(102399) {}
            Dim stream As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)
            stream.Read(buffer, 0, Convert.ToInt32(102400))
            web.GetFile(buffer, "scan.pdf", "USER_ID", "USER_NAME")

    This code worked fine on my end:

    Dim web As New WebService()
    Dim filePath As String = Server.MapPath("~/scan.pdf")
    Dim binReader As New BinaryReader(File.Open(filePath, FileMode.Open, FileAccess.Read))
    binReader.BaseStream.Position = 0
    Dim binFile As Byte() = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length))
    binReader.Close()
    web.GetFile(binFile, "Scan.pdf", 1, "testUser")

    Remember that you are passing "USER_ID" as string which is wrong.. as web service is accepting that parameter as integer.. that might be causing the issue.

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 3:37 AM
  • User-1509636757 posted

    inside user_id folder

    you are all correct, EXCEPT the user_id folder part.. there will not be any user_id folder as looking at your below line of code:

     Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/", USER_ID)))

    This will simply create id folder on root of  your application like I tested.. I passed 1 as user id; which created a folder with name "1" in root of the application.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 4:27 AM

All replies

  • User1212352859 posted

    1.Create a console application

    2. add service reference

    3.create object fo the class and call getfile method

    4. convert any textfile to byte array and pass

    Wednesday, December 4, 2013 5:38 AM
  • User-484054684 posted

    Just create a test website and add web reference (service reference and then go to Advanced Section) - your service proxy will be created.

    Then, you can just call your webmethod like a normal method by supplying inputs.

    You may refer my earlier resolved post: http://forums.asp.net/t/1954496.aspx?Read+and+Invoke+Web+Service

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 4, 2013 5:38 AM
  • User-484054684 posted

    Go with http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html 
    Especially from this section "How to Use Web service in web application?" from the above article.

    Wednesday, December 4, 2013 11:12 AM
  • User-417640953 posted

    <WebMethod()> _
    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer, ByVal USER_NAME As String)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/{1}/", USER_ID, USER_NAME)))
            If Not dinfo.Exists Then
                dinfo.Create()
            End If
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(dinfo.FullName, fileName), fileBytes)
        End Sub

    Hi love4asp.net,

    Thank you post the issue to our forum.

    Based on your code, I see the web method is used to upload file by the users. If you want to test it, I suggest you add

    the web service reference to your client application, and create a server proxy using the server namespace.

    I made a demo for this issue.

     protected void Page_Load(object sender, EventArgs e)
            {
                string filePath = Server.MapPath("~/12-month/12-3/TestPage.pdf");
                byte[] buffer = new byte[102400]; 
                FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                stream.Read(buffer, 0, Convert.ToInt32(102400));
                NSMyWebService.MyWebserviceSoapClient proxy = new NSMyWebService.MyWebserviceSoapClient();
                proxy.GetFile(buffer,"myfile.pdf","userid","username");
            }

    You can upload a file to the server by above code. And see whether the file uploaded to server.

    For how to add web service reference to your web application, please refer to below link.

    http://msdn.microsoft.com/en-us/library/bb628649.aspx

     

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 4, 2013 9:12 PM
  • User442781244 posted

    Fuxiang Zhan...

    i added webservice ref to my new website project..... then on default.aspx.vb ........i wrote this code

    Imports System.IO
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim filePath As String = Server.MapPath("~/12-month/12-3/TestPage.pdf")
            Dim buffer As Byte() = New Byte(102399) {}
            Dim stream As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)
            stream.Read(buffer, 0, Convert.ToInt32(102400))
            Dim proxy As New NSMyWebService.MyWebserviceSoapClient()
            proxy.GetFile(buffer, "myfile.pdf", "userid", "username")
        End Sub
    
    End Class
    
    

    getting error in this line:

     NSMyWebService.MyWebserviceSoapClient() is not defined.

    Thursday, December 5, 2013 12:06 AM
  • User-417640953 posted

    NSMyWebService.MyWebserviceSoapClient() is not defined.

    Thanks for your response.

    The "NSMyWebService.MyWebserviceSoapClient()" is the client side server proxy generated by my Visual Studio when I add the web service reference.

    You can find it in your project folder "Service References", maybe your generated web service proxy namespace and class different from mine "NSMyWebService.MyWebserviceSoapClient()".

     

    Thanks.

    Best Regards!

     

    Thursday, December 5, 2013 12:23 AM
  • User442781244 posted

    vs is suggesting me this at this place  Dim proxy As New NSMyWebService.MyWebserviceSoapClient()

                                                           Dim proxy As NewSystem.Web.Services.WebServiceAttribute()

    if i will adpot it .then i am getting error in this line

    proxy.GetFile(buffer, "myfile.pdf", "userid", "username")

    my webservice  name is:

    WebService.asmx

    suggest me

    Thursday, December 5, 2013 12:27 AM
  • User-1509636757 posted

    Try adding Web Reference as:

    Right Click on the testing project > Add Service Reference > Click Advance button in let hand side bottom > Click on Add Web Reference in left hand side bottom > Provide the url of your asmx service > Add the Web Reference. This should add the reference of the asmx service. Then simply write the code just like you are creating the object of a class and calling the method of that class. Simply create object of your web service class and call the webmethod of that class.

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 12:50 AM
  • User442781244 posted

    hi

    kaushal.. above see webmethod properly

    i have written this code plz validate..   WebService() is class of webservice.vb file ..i have crteated object of that class and called getfile webmethod using webervice class obji.e web ...this is correct??

    what should be server,Mappath???? my newly created test asp..net website project or....webservice project.

    kindly suggest

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim web As New WebService()
            Dim filePath As String = Server.MapPath("~/12-month/12-3/TestPage.pdf")
            Dim buffer As Byte() = New Byte(102399) {}
            Dim stream As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)
            stream.Read(buffer, 0, Convert.ToInt32(102400))
            web.GetFile(buffer, "myfile.pdf", "userid", "username")
        End Sub

    Thursday, December 5, 2013 1:27 AM
  • User-1509636757 posted

            Dim filePath As String = Server.MapPath("~/12-month/12-3/TestPage.pdf")

    I understand that you are trying to convert a file in to array of bytes and pass it as web service method argument. So, here you have to provide the path of the file; the file which you want to pass to web service.. take this example; I have taken a test website where I have added the web reference of this web service; now, I have a file inside my website root called "test.pdf", then I will simply write         Dim filePath As String = Server.MapPath("~/test.pdf") to get the file path and to convert into bytes and pass it as argument in webmethod.

    hope it helps./.

    Thursday, December 5, 2013 1:34 AM
  • User442781244 posted

    kaushal ,i am getting blank page when i run aspx page of test asp.net website..

    when i checked at test asp.net website no folder is created and i also checked in webservice project..

    test asp.net  wensite

    .vb page

    Imports System.IO
    Imports localhost
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim web As New WebService()
            Dim filePath As String = Server.MapPath(("~/scan.pdf"))
            Dim buffer As Byte() = New Byte(102399) {}
            Dim stream As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)
            stream.Read(buffer, 0, Convert.ToInt32(102400))
            web.GetFile(buffer, "scan.pdf", "USER_ID", "USER_NAME")        
        End Sub
    End Class

    asmx page

    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Data.OleDb
    Imports System.Data
    Imports System.IO
    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <WebService(Namespace:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class WebService
        Inherits System.Web.Services.WebService
    
        <WebMethod()> _
        Public Function HelloWorld() As String
            Return "Hello World"
        End Function    
        <WebMethod()> _
    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer, ByVal USER_NAME As String)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/{1}/", USER_ID, USER_NAME)))
            If Not dinfo.Exists Then
                dinfo.Create()
            End If
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(dinfo.FullName, fileName), fileBytes)
        End Sub
    End Class
    
    

    kindly share idea what is wrong??

    Thursday, December 5, 2013 1:49 AM
  • User-417640953 posted

    Hi,

    First of all, you should add the web service reference to your project as kaushal suggested.

    Then Visual Studio will generate a folder named "Service References" like below.

    https://skydrive.live.com/redir?resid=C6E905364604D18E!107&authkey=!AEqct_iQbRMhIhk&v=3&ithint=photo%2c.png

    Then you can use the generated proxy class.

    You can also check below link.

    http://www.codeproject.com/Articles/14957/Web-Services-in-C-and-Net

    Thanks.

    Best Regards!

     

    Thursday, December 5, 2013 1:58 AM
  • User-1509636757 posted

    Seems like you are almost there if you are not having any compiler or runtime error. Now put a breakpoint at this line in web srevice and run the application and see if you have any error of something which is wrong also check that you are receiving all parameters correctly in webmethod. BE SURE that you will press F11 while debugging to call the webmethod:

     Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/{1}/", USER_ID, USER_NAME)))
    Thursday, December 5, 2013 2:00 AM
  • User442781244 posted

    kaushal ,i tried putting breakpoint  and when  page loaded ..i pressed f11 but no action.....breakpint is not fired at all on f11

    i request u to see my above code once again

    Thursday, December 5, 2013 2:14 AM
  • User-1509636757 posted

    put breakpoint here in page_load in your test application and see line by line pressing F11 that does the control really goes to your webservice method:

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Thursday, December 5, 2013 2:16 AM
  • User442781244 posted

    Fuxiang ,i treied as kaushal suggested but at my end no such folder is generated

    Thursday, December 5, 2013 2:18 AM
  • User-1509636757 posted

    Fuxiang ,i treied as kaushal suggested but at my end no such folder is generated

    Oh man! can you please upload an image of your test application solution explorer? will help a bit to get the idea :)

    Thursday, December 5, 2013 2:20 AM
  • User442781244 posted

    kaushal..

    1>

    test asp.net website...i put breakpt at oageload..but breakpt is not firing at all on f11.

    i tried to build page....so no error from test website.

    2>i also do the same things in websrvice project....

    now what to do???

    Thursday, December 5, 2013 3:03 AM
  • User-1509636757 posted

    you might be using older version of visual studio. Can you check it Debug mode is set to true in web.config: <compilation debug="true"

    Thursday, December 5, 2013 3:07 AM
  • User442781244 posted

    <compilation debug="true" in webconfig...

    Thursday, December 5, 2013 3:15 AM
  • User-1509636757 posted

    well, I really unable to understand what is your real problem that stopping you from debugging but here is a complete solution and i tested it by passing a test pdf from test web application to the SAME web service that you have created.. http://weblogs.asp.net/blogs/kaushal/WebApplication16.zip

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 3:29 AM
  • User-1509636757 posted

       Dim web As New WebService()
            Dim filePath As String = Server.MapPath(("~/scan.pdf"))
            Dim buffer As Byte() = New Byte(102399) {}
            Dim stream As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)
            stream.Read(buffer, 0, Convert.ToInt32(102400))
            web.GetFile(buffer, "scan.pdf", "USER_ID", "USER_NAME")

    This code worked fine on my end:

    Dim web As New WebService()
    Dim filePath As String = Server.MapPath("~/scan.pdf")
    Dim binReader As New BinaryReader(File.Open(filePath, FileMode.Open, FileAccess.Read))
    binReader.BaseStream.Position = 0
    Dim binFile As Byte() = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length))
    binReader.Close()
    web.GetFile(binFile, "Scan.pdf", 1, "testUser")

    Remember that you are passing "USER_ID" as string which is wrong.. as web service is accepting that parameter as integer.. that might be causing the issue.

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 3:37 AM
  • User442781244 posted

    hi kaushal..

    i have 1 more query...this is my webmethod

    <WebMethod()> _
    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/", USER_ID)))
            If Not dinfo.Exists Then
                dinfo.Create()
            End If
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(dinfo.FullName, fileName), fileBytes)
        End Sub

    whenever otherwebsite user will send pdf file  suppose id-16 in first time then userid folder will created and inside this folder 16 will be created and this folder will contain pdf file??? in this way every time different folder will be created such for id  23, 45 containing pdf file inside user_id folder

    tell me if i am wrong???

    Thursday, December 5, 2013 4:23 AM
  • User-1509636757 posted

    inside user_id folder

    you are all correct, EXCEPT the user_id folder part.. there will not be any user_id folder as looking at your below line of code:

     Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/", USER_ID)))

    This will simply create id folder on root of  your application like I tested.. I passed 1 as user id; which created a folder with name "1" in root of the application.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2013 4:27 AM
  • User442781244 posted

    kaushal..

    i am receiver of pdf files.....i want that a user_id folder should be created ,inside this id folder should be created then inside this pdf..

    ..inshort

    user_id folder------>>>

                                      ------->1> id folder of user1--->pdf file....////this structure i want........at my end..

                                      --------->2> id folder of user2--->pdf file.

        so on

    so for this i have to write code or sender have to made such format while calling webmethod.???

    if i have to made such arrangement then plz guide

    Thursday, December 5, 2013 4:38 AM
  • User-1509636757 posted

    Simply change this line of code to include user_id foder as:

     Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/user_id/{0}/", USER_ID)))
    Thursday, December 5, 2013 5:46 AM
  • User442781244 posted

    kaushal,

    suppose those are sending pdf file to my website user...i want to see sysdate as well username who is sending pdf file to a particular user...

    when i will reterive pdf file for suppose id-12 ..data will display in gridview on pageload...

    gridview should display...pdffile name, sysdate, sendername, download option indside gridview,

    what to do for this???

    what i have to arrangement at my end ????

    Thursday, December 5, 2013 11:54 PM
  • User-1509636757 posted

    gridview should display...pdffile name, sysdate, sendername, download option indside gridview,

    You have written code to send pdf file: serviceObj.GetFile(binFile,"Test.pdf",1,"testUser");

    Just add two more parameter: serviceObj.GetFile(binFile,"Test.pdf",1,"testUser", DateTime.Now,"Raju"); //-- here DateTime.Now is the send time and "Raju" is the sender.

    On webservice asmx side:

        <WebMethod()> _
    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer, ByVal USER_NAME As String, ByVal SysTime as DateTime, ByVal sender as String)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/{0}/{1}/", USER_ID, USER_NAME)))
            If Not dinfo.Exists Then
                dinfo.Create()
            End If
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(dinfo.FullName, fileName), fileBytes)

    //-- you need to write code here to save the date time as well as sender here sothat you can show it in gridview.
        End Sub

    hope it helps./.

    Friday, December 6, 2013 12:06 AM
  • User442781244 posted

    prblm is that..pdf is stored in folder and sendername date will be stored in table...so when i will display data then pdf file sender and date should match...

    these two things r in different place.,..how to do it

    Friday, December 6, 2013 12:12 AM
  • User-1509636757 posted

    Yes, you need to store the file path, sys date and sender name in database.. and bind your gridview from the database.. this way it will be possible.. you can show the code where you are binding the gridview on page..

    Friday, December 6, 2013 12:15 AM
  • User442781244 posted

    i have created 1 table SENDERDETAILS

    FILEPATH    VARCHAR2(50 BYTE)
    SYSTEMDATE    TIMESTAMP(6)
    SENDERNAME    VARCHAR2(50 BYTE)

    i have tried some code kindly see :kindly validate code

    cmd.Parameters.AddWithValue("FILEPATH", ????? ) //what to write in this line of code
    <WebMethod()> _
    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer, ByVal USER_NAME As String, ByVal SysTime As DateTime, ByVal sender As String)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/user_id/{0}/{1}/", USER_ID, USER_NAME)))
            If Not dinfo.Exists Then
                dinfo.Create()
            End If
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(dinfo.FullName, fileName), fileBytes)
            Dim constr As String
            constr = "Provider=OraOLEDB.Oracle.1;Datasource=test;User ID=test;Password= test"
            Dim con As New OleDbConnection(constr)
            con.Open()
            Dim sql As String = "insert into SENDERDETAILS(FILEPATH, SYSTEMDATE,SENDERNAME) values (:FILEPATH, :SYSTEMDATE, :SENDERNAME)"
            Dim cmd As New OleDbCommand(sql, con)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("FILEPATH", )
            cmd.Parameters.AddWithValue("SYSTEMDATE", SysTime)
            cmd.Parameters.AddWithValue("SENDERNAME", sender) cmd.ExecuteNonQuery() con.Close() End Sub

    Friday, December 6, 2013 1:17 AM
  • User-1509636757 posted

    write the same path where you are writing/saving the file:

    Dim sql As String = "insert into SENDERDETAILS(FILEPATH, SYSTEMDATE,SENDERNAME) values (@FILEPATH, @SYSTEMDATE, @SENDERNAME)"
            Dim cmd As New OleDbCommand(sql, con)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@FILEPATH", System.IO.Path.Combine(dinfo.FullName, fileName))
            cmd.Parameters.AddWithValue("@SYSTEMDATE", SysTime)
            cmd.Parameters.AddWithValue("@SENDERNAME", sender)

    Friday, December 6, 2013 1:31 AM
  • User442781244 posted

    kaushal

    Public Sub GetFile(ByVal fileBytes As Byte(), ByVal fileName As String, ByVal USER_ID As Integer, ByVal USER_NAME As String, ByVal SysTime As DateTime, ByVal sender As String)
            Dim dinfo As New System.IO.DirectoryInfo(Server.MapPath(String.Format("~/user_id/{0}/{1}/", USER_ID, USER_NAME)))
            If Not dinfo.Exists Then

    this piece of code will create FOLDER AT MY END

    user_id folder ----------- 
    1>ID (ID OF MY WEBSITE USER to whom pdf file is sent)(different id folder will created.)
    2>USER_NAME(NAME OF MY WEBSITE USER to whom pdf file is sent)(different username folder will created)
    structure is like this

    now
    Dim sql As String = "insert into SENDERDETAILS(FILEPATH, SYSTEMDATE,SENDERNAME) values (@FILEPATH, @SYSTEMDATE, @SENDERNAME)"
    in
    FILEPATH what would be saved becuase pdf is saved in id folder .????


    Friday, December 6, 2013 2:21 AM
  • User-1509636757 posted

    in FILEPATH  field you save the SAME path where you are saving the pdf file.. so, you might be constructing the path to save the pdf file.. use that same variable/path to store in FILEPATH field as well..

    Friday, December 6, 2013 2:38 AM
  • User442781244 posted

    not so clear to me..Cry

    ...i just want to display pdf files in gridview based on userid..when user login into theri account..

    i am trying this code kindly validate

    protected void BindGridview()
        {
                int userID =  Convert.ToInt32(Session["ID"].ToString());/// where to use this userID so that user can see his own pdf files only not others
                string constr;
                constr = "Provider=OraOLEDB.Oracle.1;Datasource=test;User ID=test;Password= test";
                OleDbConnection con = new OleDbConnection(constr);
                con.Open();
                string sql = "select FILEPATH,SYSTEMDATE,SENDERNAME from SENDERDETAILS";
                OleDbCommand cmd = new OleDbCommand(sql, con);
                cmd.CommandType = CommandType.Text;
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                gvDetails.DataTextField =  "FILEPATH";
                gvDetails.DataValueField = "FILEPATH";
                gvDetails.DataTextField =  "SYSTEMDATE";
                gvDetails.DataValueField = "SYSTEMDATE";
                gvDetails.DataTextField =  "SENDERNAME";
                gvDetails.DataValueField = "SENDERNAME";
                DataSet ds = new DataSet();
                da.Fill(ds);
                gvDetails.DataSource = ds;
                gvDetails.DataBind();
                con.Close();
            
           
        }

    Friday, December 6, 2013 3:44 AM
  • User-1509636757 posted

    It should be something similar to:

        <asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField DataField="FILEPATH" HeaderText="FILEPATH" />
                <asp:BoundField DataField="SYSTEMDATE" HeaderText="SYSTEMDATE" />
                <asp:BoundField DataField="SENDERNAME" HeaderText="SENDERNAME" />
            </Columns>
        </asp:GridView>
    
    
    
        protected void BindGridview()
        {
            int userID = Convert.ToInt32(Session["ID"].ToString());/// where to use this userID so that user can see his own pdf files only not others
            string constr;
            constr = "Provider=OraOLEDB.Oracle.1;Datasource=test;User ID=test;Password= test";
            OleDbConnection con = new OleDbConnection(constr);
            con.Open();
            string sql = "select FILEPATH,SYSTEMDATE,SENDERNAME from SENDERDETAILS";
            OleDbCommand cmd = new OleDbCommand(sql, con);
            cmd.CommandType = CommandType.Text;
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            
            DataSet ds = new DataSet();
            da.Fill(ds);
            gvDetails.DataSource = ds;
            gvDetails.DataBind();
            con.Close();
        }

    hope it helps./.

    Friday, December 6, 2013 3:54 AM
  • User442781244 posted

    kaushal...filepath column will store pdf file or what??? how to  display gridview userwise..i.e user can see his pdf files only..suggest this also..where to use this

    //int userID =  Convert.ToInt32(Session["ID"].ToString());

    i have added

    <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
    so that pdf file can be downloaded.
    previoulsy i use this piece of code for dowloading..now what to modify?
    protected void lnkDownload_Click(object sender, System.EventArgs e)
        { 
            LinkButton lnkbtn = sender as LinkButton;
            GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
            string filePath = gvDetails.Rows[gvrow.RowIndex].Cells[0].Text;
            Response.ContentType = "pdf";
            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
            Response.TransmitFile(Server.MapPath("~/userpdf/" + filePath));
            Response.End();
            
        }


    .aspx page

    <div>
    <asp:Button ID="btnGetFiles" Text="Get Files From Folder" runat="server" onclick="btnGetFiles_Click" />
    <asp:GridView ID="gvDetails" CellPadding="5" runat="server" DataKeyNames="Text" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField="FILEPATH" HeaderText="FILEPATH" />
    <asp:BoundField DataField="SYSTEMDATE" HeaderText="SYSTEMDATE" />
    <asp:BoundField DataField="SENDERNAME" HeaderText="SENDERNAME" />
    <asp:TemplateField HeaderText="Path">
    <ItemTemplate>
    <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
    </asp:GridView>
    </div>

    Friday, December 6, 2013 4:13 AM
  • User-1509636757 posted

    filepath column will store pdf file or what???

    that will only store the filepath not the pdf file itself.. also, i just come to know that you also need to store USERID for which the file is coming in the table; so , just add one more field in your table USERID and store the USERID in GetFile method of your web service as:

    Dim sql As String = "insert into SENDERDETAILS(FILEPATH, SYSTEMDATE,SENDERNAME, USERID) values (@FILEPATH, @SYSTEMDATE, @SENDERNAME, @UserID)"
            Dim cmd As New OleDbCommand(sql, con)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@FILEPATH", System.IO.Path.Combine(dinfo.FullName, fileName))
            cmd.Parameters.AddWithValue("@SYSTEMDATE", SysTime)
            cmd.Parameters.AddWithValue("@SENDERNAME", sender)
            cmd.Parameters.AddWithValue("@USERID", USERID)

    so, in BingGridView method you can write query like:

            string sql = "select FILEPATH,SYSTEMDATE,SENDERNAME from SENDERDETAILS WHERE USERID = " + Session["ID"].ToString();

    hope it helps./.

    Friday, December 6, 2013 4:23 AM
  • User442781244 posted

    kaushal,

    I have added 1 ctrl i.e LinkButton in gridview so that i can download pdf file ...

    <asp:TemplateField HeaderText="Path">
    <ItemTemplate>
    <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>

    for downloading previouly i wrote this code.plz suggest where to modfiy ????

    protected void lnkDownload_Click(object sender, System.EventArgs e)
        { 
            LinkButton lnkbtn = sender as LinkButton;
            GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
            string filePath = gvDetails.Rows[gvrow.RowIndex].Cells[0].Text;
            Response.ContentType = "pdf";
            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
            Response.TransmitFile(Server.MapPath("~/userpdf/" + filePath));
            Response.End();
            
        }

    Friday, December 6, 2013 5:28 AM
  • User-1509636757 posted

    debug and see what value you are receiving here:

            string filePath = gvDetails.Rows[gvrow.RowIndex].Cells[0].Text;
    Friday, December 6, 2013 5:45 AM
  • User442781244 posted

    this code is working fine kaushal,,,,,,,,

    i have mentioned:

    Response.TransmitFile(Server.MapPath("~/userpdf/" + filePath));//i have tested this with this url
    through this i downloaded my pdf file..but we ve modified code very much thats why i am not gettimg what to write in this,,
    thats what i am asking kaushal???
    Friday, December 6, 2013 5:47 AM