Solved

How to call the code?

Posted on 2014-07-29
9
167 Views
Last Modified: 2014-07-29
I have a class file in my solution GetFile.cs
In here is a function called CopyFile()

In order to test CopyFile() I added a webform to the solution and in the page_load event in the code behind I am trying to call CopyFile() but no matter how I try intellisense is not offering it up.
I have tried CopyFile() and I have tried creating a new instance of GetFile as below but still I can't "reach" it

 public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetFile theFile = new GetFile();

Open in new window


Here is CopyFile()

namespace HubbleDocs
{
    public class GetFile
    {

        
        public void CopyFile()
        {
...
}

Open in new window

0
Comment
Question by:QPR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40228210
Add a using statement to the top of your _default class:

using HubbleDocs;

Open in new window

0
 
LVL 29

Author Comment

by:QPR
ID: 40228221
Sorry I should have posted the whole of default.aspx.cs as I already have that using statement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HubbleDocs;

namespace HubbleDocs
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetFile theFile = new GetFile();
            
        }
    }
}

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40228227
Is GetFile defined with the same assembly (i.e. project)?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Author Comment

by:QPR
ID: 40228232
Yep, solution/project is called HubbleDocs which consists of GetFile.cs and default.aspx/cs (and a web service reference)
0
 
LVL 29

Author Comment

by:QPR
ID: 40228237
solution files
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40228254
Is it possible to post the entire GetFile definition?
0
 
LVL 29

Author Comment

by:QPR
ID: 40228258
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;


namespace HubbleDocs
{
    public class GetFile
    {

        
        public void CopyFile()
        {
            string webUrl = "http://xxx";
            FileCopy.Copy copyService = new FileCopy.Copy();
            copyService.Url = webUrl +"/_vti_bin/copy.asmx";
            NetworkCredential m_credentials = new NetworkCredential("x", "x", "x");
                 copyService.Credentials = m_credentials;

            //Source and Destination Document URLs
             string sourceUrl = "http://xxx/Documents/Sample.docx";
             string destinationUrl = "C:\\Documents\\Sample.doc";

            //Variables for Reading metadata’s of a document
             FileCopy.FieldInformation fieldInfo = new FileCopy.FieldInformation();
             FileCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
             FileCopy.CopyResult cResult1 = new FileCopy.CopyResult();
             FileCopy.CopyResult cResult2 = new FileCopy.CopyResult();
             FileCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

        

            //Receive a Document Contents  into Byte array (filecontents)
             byte[] fileContent; // no need to initialize the GetItem takes care of that.
             copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContent);

            //Create a new file and write contents to that document
             FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
            fStream.Write(fileContent, 0, fileContent.Length);
            fStream.Close();
        }
    }
}

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40228271
Based on what you've posted, I don't see anything wrong. You should only have to invoke against the instance.

e.g.

GetFile theFile = new GetFile();

theFile.CopyFile();

Open in new window

0
 
LVL 29

Author Comment

by:QPR
ID: 40228276
and now that I type it again I see it and it works!
So either my tired eyes didn't see it in the intellisense or the intellisense hadn't refreshed.
Oh well - all good now :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question